@elysiajs/eden 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-LJDYVDXQ.mjs +6 -0
- package/dist/index.global.js +2 -2
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -1
- package/dist/treaty2.global.js +4 -4
- package/dist/treaty2.js +4 -4
- package/dist/treaty2.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-ZIS6B6IO.mjs +0 -6
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{a as W,b as M,c as A,d as q}from"./chunk-QSLHAOSM.mjs";var F=class{constructor(t){this.url=t;this.ws=new WebSocket(t)}ws;send(t){return Array.isArray(t)?(t.forEach(n=>this.send(n)),this):(this.ws.send(typeof t=="object"?JSON.stringify(t):t.toString()),this)}on(t,n,s){return this.addEventListener(t,n,s)}off(t,n,s){return this.ws.removeEventListener(t,n,s),this}subscribe(t,n){return this.addEventListener("message",t,n)}addEventListener(t,n,s){return this.ws.addEventListener(t,f=>{if(t==="message"){let o=q(f);n({...f,data:o})}else n(f)},s),this}removeEventListener(t,n,s){return this.off(t,n,s),this}close(){return this.ws.close(),this}};var J=["get","post","put","delete","patch","options","head","connect","subscribe"],D=["localhost","127.0.0.1","0.0.0.0"],K=typeof FileList>"u",I=e=>K?e instanceof Blob:e instanceof FileList||e instanceof File,P=e=>{if(!e)return!1;for(let t in e)if(I(e[t])||Array.isArray(e[t])&&e[t].find(I))return!0;return!1},C=e=>K?e:new Promise(t=>{let n=new FileReader;n.onload=()=>{let s=new File([n.result],e.name,{lastModified:e.lastModified,type:e.type});t(s)},n.readAsArrayBuffer(e)}),b=(e,t,n={},s={})=>{if(Array.isArray(e)){for(let f of e)if(!Array.isArray(f))s=b(f,t,n,s);else{let o=f[0];if(typeof o=="string")s[o.toLowerCase()]=f[1];else for(let[i,h]of o)s[i.toLowerCase()]=h}return s}if(!e)return s;switch(typeof e){case"function":if(e instanceof Headers)return b(e,t,n,s);let f=e(t,n);return f?b(f,t,n,s):s;case"object":if(e instanceof Headers)return e.forEach((o,i)=>{s[i.toLowerCase()]=o}),s;for(let[o,i]of Object.entries(e))s[o.toLowerCase()]=i;return s;default:return s}};async function*U(e){let t=e.body;if(!t)return;let n=t.getReader(),s=new TextDecoder;try{for(;;){let{done:f,value:o}=await n.read();if(f)break;let i=typeof o=="string"?o:s.decode(o);i.includes(`
|
|
2
|
+
|
|
3
|
+
`)?yield*_(i):yield A(i)}}finally{n.releaseLock()}}function*_(e){let t=e.split(`
|
|
4
|
+
|
|
5
|
+
`);for(let n of t){if(n.indexOf(":")<=0){n&&(yield A(n));continue}let s=n.split(`
|
|
6
|
+
`),f={};for(let o of s){let i=o.indexOf(":");if(i>0){let h=o.slice(0,i).trim(),L=o.slice(i+1).trim();f[h]=A(L)}}yield f}}var x=(e,t,n=[],s)=>new Proxy(()=>{},{get(f,o){return x(e,t,o==="index"?n:[...n,o],s)},apply(f,o,[i,h]){if(!i||h||typeof i=="object"&&Object.keys(i).length!==1||J.includes(n.at(-1))){let L=[...n],k=L.pop(),v="/"+L.join("/"),{fetcher:N=fetch,headers:R,onRequest:g,onResponse:E,fetch:H}=t,m=k==="get"||k==="head"||k==="subscribe";R=b(R,v,h);let T=m?i?.query:h?.query,O="";if(T){let r=(w,u)=>{O+=(O?"&":"?")+`${encodeURIComponent(w)}=${encodeURIComponent(u)}`};for(let[w,u]of Object.entries(T)){if(Array.isArray(u)){for(let y of u)r(w,y);continue}if(u!=null){if(typeof u=="object"){r(w,JSON.stringify(u));continue}r(w,`${u}`)}}}if(k==="subscribe"){let r=e.replace(/^([^]+):\/\//,e.startsWith("https://")?"wss://":e.startsWith("http://")||D.find(w=>e.includes(w))?"ws://":"wss://")+v+O;return new F(r)}return(async()=>{let r={method:k?.toUpperCase(),body:i,...H,headers:R};r.headers={...R,...b(m?i?.headers:h?.headers,v,r)};let w=m&&typeof i=="object"?i.fetch:h?.fetch;if(r={...r,...w},m&&delete r.body,g){Array.isArray(g)||(g=[g]);for(let l of g){let a=await l(v,r);typeof a=="object"&&(r={...r,...a,headers:{...r.headers,...b(a.headers,v,r)}})}}if(m&&delete r.body,P(i)){let l=new FormData;for(let[a,c]of Object.entries(r.body)){if(Array.isArray(c)){for(let d=0;d<c.length;d++){let j=c[d];l.append(a,j instanceof File?await C(j):j)}continue}if(K){if(Array.isArray(c))for(let d of c)l.append(a,d);else l.append(a,c);continue}if(c instanceof File){l.append(a,await C(c));continue}if(c instanceof FileList){for(let d=0;d<c.length;d++)l.append(a,await C(c[d]));continue}l.append(a,c)}r.body=l}else typeof i=="object"?(r.headers["content-type"]="application/json",r.body=JSON.stringify(i)):i!=null&&(r.headers["content-type"]="text/plain");if(m&&delete r.body,g){Array.isArray(g)||(g=[g]);for(let l of g){let a=await l(v,r);typeof a=="object"&&(r={...r,...a,headers:{...r.headers,...b(a.headers,v,r)}})}}h?.headers?.["content-type"]&&(r.headers["content-type"]=h?.headers["content-type"]);let u=e+v+O,y=await(s?.handle(new Request(u,r))??N(u,r)),p=null,S=null;if(E){Array.isArray(E)||(E=[E]);for(let l of E)try{let a=await l(y.clone());if(a!=null){p=a;break}}catch(a){a instanceof W?S=a:S=new W(422,a);break}}if(p!==null)return{data:p,error:S,response:y,status:y.status,headers:y.headers};switch(y.headers.get("Content-Type")?.split(";")[0]){case"text/event-stream":p=U(y);break;case"application/json":p=JSON.parse(await y.text(),(a,c)=>{if(typeof c!="string")return c;let d=M(c);return d||c});break;case"application/octet-stream":p=await y.arrayBuffer();break;case"multipart/form-data":let l=await y.formData();p={},l.forEach((a,c)=>{p[c]=a});break;default:p=await y.text().then(A)}return(y.status>=300||y.status<200)&&(S=new W(y.status,p),p=null),{data:p,error:S,response:y,status:y.status,headers:y.headers}})()}return typeof i=="object"?x(e,t,[...n,Object.values(i)[0]],s):x(e,t,n)}}),Q=(e,t={})=>typeof e=="string"?(t.keepDomain||(e.includes("://")||(e=(D.find(n=>e.includes(n))?"http://":"https://")+e),e.endsWith("/")&&(e=e.slice(0,-1))),x(e,t)):(typeof window<"u"&&console.warn("Elysia instance server found on client side, this is not recommended for security reason. Use generic type instead."),x("http://e.ly",t,[],e));export{U as a,Q as b};
|
package/dist/index.global.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var Eden=(()=>{var J=Object.defineProperty;var
|
|
1
|
+
"use strict";var Eden=(()=>{var J=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var ae=(e,t)=>{for(var n in t)J(e,n,{get:t[n],enumerable:!0})},ie=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of re(t))!se.call(e,a)&&a!==n&&J(e,a,{get:()=>t[a],enumerable:!(r=ne(t,a))||r.enumerable});return e};var oe=e=>ie(J({},"__esModule",{value:!0}),e);var Se={};ae(Se,{edenFetch:()=>te,edenTreaty:()=>ee,treaty:()=>Q});var R=class extends Error{constructor(n,r){super(r+"");this.status=n;this.value=r}};var ce=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,fe=/(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT(?:\+|-)\d{4}\s\([^)]+\)/,de=/^(?:(?:(?:(?:0?[1-9]|[12][0-9]|3[01])[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:19|20)\d{2})|(?:(?:19|20)\d{2}[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:0?[1-9]|[12][0-9]|3[01]))))(?:\s(?:1[012]|0?[1-9]):[0-5][0-9](?::[0-5][0-9])?(?:\s[AP]M)?)?$/,ye=e=>e.trim().length!==0&&!Number.isNaN(Number(e)),D=e=>{if(typeof e!="string")return null;let t=e.replace(/"/g,"");if(ce.test(t)||fe.test(t)||de.test(t)){let n=new Date(t);if(!Number.isNaN(n.getTime()))return n}return null},ue=e=>{let t=e.charCodeAt(0),n=e.charCodeAt(e.length-1);return t===123&&n===125||t===91&&n===93},le=e=>JSON.parse(e,(t,n)=>{let r=D(n);return r||n}),L=e=>{if(!e)return e;if(ye(e))return+e;if(e==="true")return!0;if(e==="false")return!1;let t=D(e);if(t)return t;if(ue(e))try{return le(e)}catch{}return e},I=e=>{let t=e.data.toString();return t==="null"?null:L(t)};var P=class{constructor(t){this.url=t;this.ws=new WebSocket(t)}ws;send(t){return Array.isArray(t)?(t.forEach(n=>this.send(n)),this):(this.ws.send(typeof t=="object"?JSON.stringify(t):t.toString()),this)}on(t,n,r){return this.addEventListener(t,n,r)}off(t,n,r){return this.ws.removeEventListener(t,n,r),this}subscribe(t,n){return this.addEventListener("message",t,n)}addEventListener(t,n,r){return this.ws.addEventListener(t,a=>{if(t==="message"){let s=I(a);n({...a,data:s})}else n(a)},r),this}removeEventListener(t,n,r){return this.off(t,n,r),this}close(){return this.ws.close(),this}};var pe=["get","post","put","delete","patch","options","head","connect","subscribe"],Z=["localhost","127.0.0.1","0.0.0.0"],H=typeof FileList>"u",G=e=>H?e instanceof Blob:e instanceof FileList||e instanceof File,he=e=>{if(!e)return!1;for(let t in e)if(G(e[t])||Array.isArray(e[t])&&e[t].find(G))return!0;return!1},U=e=>H?e:new Promise(t=>{let n=new FileReader;n.onload=()=>{let r=new File([n.result],e.name,{lastModified:e.lastModified,type:e.type});t(r)},n.readAsArrayBuffer(e)}),M=(e,t,n={},r={})=>{if(Array.isArray(e)){for(let a of e)if(!Array.isArray(a))r=M(a,t,n,r);else{let s=a[0];if(typeof s=="string")r[s.toLowerCase()]=a[1];else for(let[i,y]of s)r[i.toLowerCase()]=y}return r}if(!e)return r;switch(typeof e){case"function":if(e instanceof Headers)return M(e,t,n,r);let a=e(t,n);return a?M(a,t,n,r):r;case"object":if(e instanceof Headers)return e.forEach((s,i)=>{r[i.toLowerCase()]=s}),r;for(let[s,i]of Object.entries(e))r[s.toLowerCase()]=i;return r;default:return r}};async function*ge(e){let t=e.body;if(!t)return;let n=t.getReader(),r=new TextDecoder;try{for(;;){let{done:a,value:s}=await n.read();if(a)break;let i=typeof s=="string"?s:r.decode(s);i.includes(`
|
|
2
2
|
|
|
3
3
|
`)?yield*me(i):yield L(i)}}finally{n.releaseLock()}}function*me(e){let t=e.split(`
|
|
4
4
|
|
|
5
5
|
`);for(let n of t){if(n.indexOf(":")<=0){n&&(yield L(n));continue}let r=n.split(`
|
|
6
|
-
`),a={};for(let s of r){let i=s.indexOf(":");if(i>0){let y=s.slice(0,i).trim(),j=s.slice(i+1).trim();a[y]=L(j)}}yield a}}var K=(e,t,n=[],r)=>new Proxy(()=>{},{get(a,s){return K(e,t,s==="index"?n:[...n,s],r)},apply(a,s,[i,y]){if(!i||y||typeof i=="object"&&Object.keys(i).length!==1||
|
|
6
|
+
`),a={};for(let s of r){let i=s.indexOf(":");if(i>0){let y=s.slice(0,i).trim(),j=s.slice(i+1).trim();a[y]=L(j)}}yield a}}var K=(e,t,n=[],r)=>new Proxy(()=>{},{get(a,s){return K(e,t,s==="index"?n:[...n,s],r)},apply(a,s,[i,y]){if(!i||y||typeof i=="object"&&Object.keys(i).length!==1||pe.includes(n.at(-1))){let j=[...n],A=j.pop(),w="/"+j.join("/"),{fetcher:k=fetch,headers:T,onRequest:m,onResponse:b,fetch:S}=t,h=A==="get"||A==="head"||A==="subscribe";T=M(T,w,y);let N=h?i?.query:y?.query,x="";if(N){let o=(O,E)=>{x+=(x?"&":"?")+`${encodeURIComponent(O)}=${encodeURIComponent(E)}`};for(let[O,E]of Object.entries(N)){if(Array.isArray(E)){for(let c of E)o(O,c);continue}if(E!=null){if(typeof E=="object"){o(O,JSON.stringify(E));continue}o(O,`${E}`)}}}if(A==="subscribe"){let o=e.replace(/^([^]+):\/\//,e.startsWith("https://")?"wss://":e.startsWith("http://")||Z.find(O=>e.includes(O))?"ws://":"wss://")+w+x;return new P(o)}return(async()=>{let o={method:A?.toUpperCase(),body:i,...S,headers:T};o.headers={...T,...M(h?i?.headers:y?.headers,w,o)};let O=h&&typeof i=="object"?i.fetch:y?.fetch;if(o={...o,...O},h&&delete o.body,m){Array.isArray(m)||(m=[m]);for(let u of m){let f=await u(w,o);typeof f=="object"&&(o={...o,...f,headers:{...o.headers,...M(f.headers,w,o)}})}}if(h&&delete o.body,he(i)){let u=new FormData;for(let[f,d]of Object.entries(o.body)){if(Array.isArray(d)){for(let l=0;l<d.length;l++){let v=d[l];u.append(f,v instanceof File?await U(v):v)}continue}if(H){if(Array.isArray(d))for(let l of d)u.append(f,l);else u.append(f,d);continue}if(d instanceof File){u.append(f,await U(d));continue}if(d instanceof FileList){for(let l=0;l<d.length;l++)u.append(f,await U(d[l]));continue}u.append(f,d)}o.body=u}else typeof i=="object"?(o.headers["content-type"]="application/json",o.body=JSON.stringify(i)):i!=null&&(o.headers["content-type"]="text/plain");if(h&&delete o.body,m){Array.isArray(m)||(m=[m]);for(let u of m){let f=await u(w,o);typeof f=="object"&&(o={...o,...f,headers:{...o.headers,...M(f.headers,w,o)}})}}y?.headers?.["content-type"]&&(o.headers["content-type"]=y?.headers["content-type"]);let E=e+w+x,c=await(r?.handle(new Request(E,o))??k(E,o)),g=null,p=null;if(b){Array.isArray(b)||(b=[b]);for(let u of b)try{let f=await u(c.clone());if(f!=null){g=f;break}}catch(f){f instanceof R?p=f:p=new R(422,f);break}}if(g!==null)return{data:g,error:p,response:c,status:c.status,headers:c.headers};switch(c.headers.get("Content-Type")?.split(";")[0]){case"text/event-stream":g=ge(c);break;case"application/json":g=JSON.parse(await c.text(),(f,d)=>{if(typeof d!="string")return d;let l=D(d);return l||d});break;case"application/octet-stream":g=await c.arrayBuffer();break;case"multipart/form-data":let u=await c.formData();g={},u.forEach((f,d)=>{g[d]=f});break;default:g=await c.text().then(L)}return(c.status>=300||c.status<200)&&(p=new R(c.status,g),g=null),{data:g,error:p,response:c,status:c.status,headers:c.headers}})()}return typeof i=="object"?K(e,t,[...n,Object.values(i)[0]],r):K(e,t,n)}}),Q=(e,t={})=>typeof e=="string"?(t.keepDomain||(e.includes("://")||(e=(Z.find(n=>e.includes(n))?"http://":"https://")+e),e.endsWith("/")&&(e=e.slice(0,-1))),K(e,t)):(typeof window<"u"&&console.warn("Elysia instance server found on client side, this is not recommended for security reason. Use generic type instead."),K("http://e.ly",t,[],e));var z=(e,t,n)=>{if(e.endsWith("/")||(e+="/"),t==="index"&&(t=""),!n||!Object.keys(n).length)return`${e}${t}`;let r="";for(let[a,s]of Object.entries(n))r+=`${a}=${s}&`;return`${e}${t}?${r.slice(0,-1)}`};var V=typeof FileList>"u",X=e=>V?e instanceof Blob:e instanceof FileList||e instanceof File,Ee=e=>{if(!e)return!1;for(let t in e){if(X(e[t]))return!0;if(Array.isArray(e[t])&&e[t].find(n=>X(n)))return!0}return!1},_=e=>V?e:new Promise(t=>{let n=new FileReader;n.onload=()=>{let r=new File([n.result],e.name,{lastModified:e.lastModified,type:e.type});t(r)},n.readAsArrayBuffer(e)}),B=class{ws;url;constructor(t){this.ws=new WebSocket(t),this.url=t}send(t){return Array.isArray(t)?(t.forEach(n=>this.send(n)),this):(this.ws.send(typeof t=="object"?JSON.stringify(t):t.toString()),this)}on(t,n,r){return this.addEventListener(t,n,r)}off(t,n,r){return this.ws.removeEventListener(t,n,r),this}subscribe(t,n){return this.addEventListener("message",t,n)}addEventListener(t,n,r){return this.ws.addEventListener(t,a=>{if(t==="message"){let s=I(a);n({...a,data:s})}else n(a)},r),this}removeEventListener(t,n,r){return this.off(t,n,r),this}close(){return this.ws.close(),this}},Y=(e,t="",n)=>new Proxy(()=>{},{get(r,a,s){return Y(e,`${t}/${a.toString()}`,n)},apply(r,a,[s,i={}]=[{},{}]){let y=s!==void 0&&(typeof s!="object"||Array.isArray(s))?s:void 0,{$query:j,$fetch:A,$headers:w,$transform:k,getRaw:T,...m}=s??{};y??=m;let b=t.lastIndexOf("/"),S=t.slice(b+1).toUpperCase(),h=z(e,b===-1?"/":t.slice(0,b),Object.assign(i.query??{},j)),N=n.fetcher??fetch,x=n.transform?Array.isArray(n.transform)?n.transform:[n.transform]:void 0,o=k?Array.isArray(k)?k:[k]:void 0;return o&&(x?x=o.concat(x):x=o),S==="SUBSCRIBE"?new B(h.replace(/^([^]+):\/\//,h.startsWith("https://")?"wss://":"ws://")):(async E=>{let c,g={...n.$fetch?.headers,...A?.headers,...i.headers,...w};if(S!=="GET"&&S!=="HEAD"){c=Object.keys(y).length||Array.isArray(y)?y:void 0;let l=c&&(typeof c=="object"||Array.isArray(y));if(l&&Ee(c)){let $=new FormData;for(let[C,F]of Object.entries(c))if(V)$.append(C,F);else if(F instanceof File)$.append(C,await _(F));else if(F instanceof FileList)for(let W=0;W<F.length;W++)$.append(C,await _(F[W]));else if(Array.isArray(F))for(let W=0;W<F.length;W++){let q=F[W];$.append(C,q instanceof File?await _(q):q)}else $.append(C,F);c=$}else c!=null&&(g["content-type"]=l?"application/json":"text/plain",c=l?JSON.stringify(c):y)}let p=await N(h,{method:S,body:c,...n.$fetch,...i.fetch,...A,headers:g}),u;if(E.getRaw)return p;switch(p.headers.get("Content-Type")?.split(";")[0]){case"application/json":u=await p.json();break;default:u=await p.text().then(L)}let f=p.status>=300||p.status<200?new R(p.status,u):null,d={data:u,error:f,response:p,status:p.status,headers:p.headers};if(x)for(let l of x){let v=l(d);v instanceof Promise&&(v=await v),v!=null&&(d=v)}return d})({getRaw:T})}}),ee=(e,t={fetcher:fetch})=>new Proxy({},{get(n,r){return Y(e,r,t)}});var we=async e=>{switch(e.headers.get("Content-Type")?.split(";")[0]){case"application/json":return e.json();case"application/octet-stream":return e.arrayBuffer();case"multipart/form-data":{let n=await e.formData(),r={};return n.forEach((a,s)=>{r[s]=a}),r}}return e.text().then(L)},be=async(e,t)=>{let n=await we(e);return e.status>300?{data:null,status:e.status,headers:e.headers,retry:t,error:new R(e.status,n)}:{data:n,error:null,status:e.status,headers:e.headers,retry:t}},te=(e,t)=>(n,{query:r,params:a,body:s,...i}={})=>{a&&Object.entries(a).forEach(([S,h])=>{n=n.replace(`:${S}`,h)});let y=t?.fetcher||globalThis.fetch,j=r?Object.fromEntries(Object.entries(r).filter(([S,h])=>h!=null)):null,A=j?`?${new URLSearchParams(j).toString()}`:"",w=`${e}${n}${A}`,k=new Headers(i.headers||{}),T=k.get("content-type");if(!(s instanceof FormData)&&!(s instanceof URLSearchParams)&&(!T||T==="application/json"))try{s=JSON.stringify(s),T||k.set("content-type","application/json")}catch{}let m={...i,method:i.method?.toUpperCase()||"GET",headers:k,body:s},b=()=>y(w,m).then(S=>be(S,b));return b()};return oe(Se);})();
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var J=Object.defineProperty;var
|
|
1
|
+
"use strict";var J=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var ae=(e,t)=>{for(var n in t)J(e,n,{get:t[n],enumerable:!0})},ie=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of re(t))!se.call(e,a)&&a!==n&&J(e,a,{get:()=>t[a],enumerable:!(r=ne(t,a))||r.enumerable});return e};var oe=e=>ie(J({},"__esModule",{value:!0}),e);var Se={};ae(Se,{edenFetch:()=>te,edenTreaty:()=>ee,treaty:()=>Q});module.exports=oe(Se);var R=class extends Error{constructor(n,r){super(r+"");this.status=n;this.value=r}};var ce=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,fe=/(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT(?:\+|-)\d{4}\s\([^)]+\)/,de=/^(?:(?:(?:(?:0?[1-9]|[12][0-9]|3[01])[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:19|20)\d{2})|(?:(?:19|20)\d{2}[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:0?[1-9]|[12][0-9]|3[01]))))(?:\s(?:1[012]|0?[1-9]):[0-5][0-9](?::[0-5][0-9])?(?:\s[AP]M)?)?$/,ye=e=>e.trim().length!==0&&!Number.isNaN(Number(e)),D=e=>{if(typeof e!="string")return null;let t=e.replace(/"/g,"");if(ce.test(t)||fe.test(t)||de.test(t)){let n=new Date(t);if(!Number.isNaN(n.getTime()))return n}return null},ue=e=>{let t=e.charCodeAt(0),n=e.charCodeAt(e.length-1);return t===123&&n===125||t===91&&n===93},le=e=>JSON.parse(e,(t,n)=>{let r=D(n);return r||n}),L=e=>{if(!e)return e;if(ye(e))return+e;if(e==="true")return!0;if(e==="false")return!1;let t=D(e);if(t)return t;if(ue(e))try{return le(e)}catch{}return e},I=e=>{let t=e.data.toString();return t==="null"?null:L(t)};var P=class{constructor(t){this.url=t;this.ws=new WebSocket(t)}ws;send(t){return Array.isArray(t)?(t.forEach(n=>this.send(n)),this):(this.ws.send(typeof t=="object"?JSON.stringify(t):t.toString()),this)}on(t,n,r){return this.addEventListener(t,n,r)}off(t,n,r){return this.ws.removeEventListener(t,n,r),this}subscribe(t,n){return this.addEventListener("message",t,n)}addEventListener(t,n,r){return this.ws.addEventListener(t,a=>{if(t==="message"){let s=I(a);n({...a,data:s})}else n(a)},r),this}removeEventListener(t,n,r){return this.off(t,n,r),this}close(){return this.ws.close(),this}};var pe=["get","post","put","delete","patch","options","head","connect","subscribe"],Z=["localhost","127.0.0.1","0.0.0.0"],H=typeof FileList>"u",G=e=>H?e instanceof Blob:e instanceof FileList||e instanceof File,he=e=>{if(!e)return!1;for(let t in e)if(G(e[t])||Array.isArray(e[t])&&e[t].find(G))return!0;return!1},U=e=>H?e:new Promise(t=>{let n=new FileReader;n.onload=()=>{let r=new File([n.result],e.name,{lastModified:e.lastModified,type:e.type});t(r)},n.readAsArrayBuffer(e)}),M=(e,t,n={},r={})=>{if(Array.isArray(e)){for(let a of e)if(!Array.isArray(a))r=M(a,t,n,r);else{let s=a[0];if(typeof s=="string")r[s.toLowerCase()]=a[1];else for(let[i,y]of s)r[i.toLowerCase()]=y}return r}if(!e)return r;switch(typeof e){case"function":if(e instanceof Headers)return M(e,t,n,r);let a=e(t,n);return a?M(a,t,n,r):r;case"object":if(e instanceof Headers)return e.forEach((s,i)=>{r[i.toLowerCase()]=s}),r;for(let[s,i]of Object.entries(e))r[s.toLowerCase()]=i;return r;default:return r}};async function*ge(e){let t=e.body;if(!t)return;let n=t.getReader(),r=new TextDecoder;try{for(;;){let{done:a,value:s}=await n.read();if(a)break;let i=typeof s=="string"?s:r.decode(s);i.includes(`
|
|
2
2
|
|
|
3
3
|
`)?yield*me(i):yield L(i)}}finally{n.releaseLock()}}function*me(e){let t=e.split(`
|
|
4
4
|
|
|
5
5
|
`);for(let n of t){if(n.indexOf(":")<=0){n&&(yield L(n));continue}let r=n.split(`
|
|
6
|
-
`),a={};for(let s of r){let i=s.indexOf(":");if(i>0){let y=s.slice(0,i).trim(),j=s.slice(i+1).trim();a[y]=L(j)}}yield a}}var K=(e,t,n=[],r)=>new Proxy(()=>{},{get(a,s){return K(e,t,s==="index"?n:[...n,s],r)},apply(a,s,[i,y]){if(!i||y||typeof i=="object"&&Object.keys(i).length!==1||
|
|
6
|
+
`),a={};for(let s of r){let i=s.indexOf(":");if(i>0){let y=s.slice(0,i).trim(),j=s.slice(i+1).trim();a[y]=L(j)}}yield a}}var K=(e,t,n=[],r)=>new Proxy(()=>{},{get(a,s){return K(e,t,s==="index"?n:[...n,s],r)},apply(a,s,[i,y]){if(!i||y||typeof i=="object"&&Object.keys(i).length!==1||pe.includes(n.at(-1))){let j=[...n],A=j.pop(),w="/"+j.join("/"),{fetcher:k=fetch,headers:T,onRequest:m,onResponse:b,fetch:S}=t,h=A==="get"||A==="head"||A==="subscribe";T=M(T,w,y);let N=h?i?.query:y?.query,x="";if(N){let o=(O,E)=>{x+=(x?"&":"?")+`${encodeURIComponent(O)}=${encodeURIComponent(E)}`};for(let[O,E]of Object.entries(N)){if(Array.isArray(E)){for(let c of E)o(O,c);continue}if(E!=null){if(typeof E=="object"){o(O,JSON.stringify(E));continue}o(O,`${E}`)}}}if(A==="subscribe"){let o=e.replace(/^([^]+):\/\//,e.startsWith("https://")?"wss://":e.startsWith("http://")||Z.find(O=>e.includes(O))?"ws://":"wss://")+w+x;return new P(o)}return(async()=>{let o={method:A?.toUpperCase(),body:i,...S,headers:T};o.headers={...T,...M(h?i?.headers:y?.headers,w,o)};let O=h&&typeof i=="object"?i.fetch:y?.fetch;if(o={...o,...O},h&&delete o.body,m){Array.isArray(m)||(m=[m]);for(let u of m){let f=await u(w,o);typeof f=="object"&&(o={...o,...f,headers:{...o.headers,...M(f.headers,w,o)}})}}if(h&&delete o.body,he(i)){let u=new FormData;for(let[f,d]of Object.entries(o.body)){if(Array.isArray(d)){for(let l=0;l<d.length;l++){let v=d[l];u.append(f,v instanceof File?await U(v):v)}continue}if(H){if(Array.isArray(d))for(let l of d)u.append(f,l);else u.append(f,d);continue}if(d instanceof File){u.append(f,await U(d));continue}if(d instanceof FileList){for(let l=0;l<d.length;l++)u.append(f,await U(d[l]));continue}u.append(f,d)}o.body=u}else typeof i=="object"?(o.headers["content-type"]="application/json",o.body=JSON.stringify(i)):i!=null&&(o.headers["content-type"]="text/plain");if(h&&delete o.body,m){Array.isArray(m)||(m=[m]);for(let u of m){let f=await u(w,o);typeof f=="object"&&(o={...o,...f,headers:{...o.headers,...M(f.headers,w,o)}})}}y?.headers?.["content-type"]&&(o.headers["content-type"]=y?.headers["content-type"]);let E=e+w+x,c=await(r?.handle(new Request(E,o))??k(E,o)),g=null,p=null;if(b){Array.isArray(b)||(b=[b]);for(let u of b)try{let f=await u(c.clone());if(f!=null){g=f;break}}catch(f){f instanceof R?p=f:p=new R(422,f);break}}if(g!==null)return{data:g,error:p,response:c,status:c.status,headers:c.headers};switch(c.headers.get("Content-Type")?.split(";")[0]){case"text/event-stream":g=ge(c);break;case"application/json":g=JSON.parse(await c.text(),(f,d)=>{if(typeof d!="string")return d;let l=D(d);return l||d});break;case"application/octet-stream":g=await c.arrayBuffer();break;case"multipart/form-data":let u=await c.formData();g={},u.forEach((f,d)=>{g[d]=f});break;default:g=await c.text().then(L)}return(c.status>=300||c.status<200)&&(p=new R(c.status,g),g=null),{data:g,error:p,response:c,status:c.status,headers:c.headers}})()}return typeof i=="object"?K(e,t,[...n,Object.values(i)[0]],r):K(e,t,n)}}),Q=(e,t={})=>typeof e=="string"?(t.keepDomain||(e.includes("://")||(e=(Z.find(n=>e.includes(n))?"http://":"https://")+e),e.endsWith("/")&&(e=e.slice(0,-1))),K(e,t)):(typeof window<"u"&&console.warn("Elysia instance server found on client side, this is not recommended for security reason. Use generic type instead."),K("http://e.ly",t,[],e));var z=(e,t,n)=>{if(e.endsWith("/")||(e+="/"),t==="index"&&(t=""),!n||!Object.keys(n).length)return`${e}${t}`;let r="";for(let[a,s]of Object.entries(n))r+=`${a}=${s}&`;return`${e}${t}?${r.slice(0,-1)}`};var V=typeof FileList>"u",X=e=>V?e instanceof Blob:e instanceof FileList||e instanceof File,Ee=e=>{if(!e)return!1;for(let t in e){if(X(e[t]))return!0;if(Array.isArray(e[t])&&e[t].find(n=>X(n)))return!0}return!1},_=e=>V?e:new Promise(t=>{let n=new FileReader;n.onload=()=>{let r=new File([n.result],e.name,{lastModified:e.lastModified,type:e.type});t(r)},n.readAsArrayBuffer(e)}),B=class{ws;url;constructor(t){this.ws=new WebSocket(t),this.url=t}send(t){return Array.isArray(t)?(t.forEach(n=>this.send(n)),this):(this.ws.send(typeof t=="object"?JSON.stringify(t):t.toString()),this)}on(t,n,r){return this.addEventListener(t,n,r)}off(t,n,r){return this.ws.removeEventListener(t,n,r),this}subscribe(t,n){return this.addEventListener("message",t,n)}addEventListener(t,n,r){return this.ws.addEventListener(t,a=>{if(t==="message"){let s=I(a);n({...a,data:s})}else n(a)},r),this}removeEventListener(t,n,r){return this.off(t,n,r),this}close(){return this.ws.close(),this}},Y=(e,t="",n)=>new Proxy(()=>{},{get(r,a,s){return Y(e,`${t}/${a.toString()}`,n)},apply(r,a,[s,i={}]=[{},{}]){let y=s!==void 0&&(typeof s!="object"||Array.isArray(s))?s:void 0,{$query:j,$fetch:A,$headers:w,$transform:k,getRaw:T,...m}=s??{};y??=m;let b=t.lastIndexOf("/"),S=t.slice(b+1).toUpperCase(),h=z(e,b===-1?"/":t.slice(0,b),Object.assign(i.query??{},j)),N=n.fetcher??fetch,x=n.transform?Array.isArray(n.transform)?n.transform:[n.transform]:void 0,o=k?Array.isArray(k)?k:[k]:void 0;return o&&(x?x=o.concat(x):x=o),S==="SUBSCRIBE"?new B(h.replace(/^([^]+):\/\//,h.startsWith("https://")?"wss://":"ws://")):(async E=>{let c,g={...n.$fetch?.headers,...A?.headers,...i.headers,...w};if(S!=="GET"&&S!=="HEAD"){c=Object.keys(y).length||Array.isArray(y)?y:void 0;let l=c&&(typeof c=="object"||Array.isArray(y));if(l&&Ee(c)){let $=new FormData;for(let[C,F]of Object.entries(c))if(V)$.append(C,F);else if(F instanceof File)$.append(C,await _(F));else if(F instanceof FileList)for(let W=0;W<F.length;W++)$.append(C,await _(F[W]));else if(Array.isArray(F))for(let W=0;W<F.length;W++){let q=F[W];$.append(C,q instanceof File?await _(q):q)}else $.append(C,F);c=$}else c!=null&&(g["content-type"]=l?"application/json":"text/plain",c=l?JSON.stringify(c):y)}let p=await N(h,{method:S,body:c,...n.$fetch,...i.fetch,...A,headers:g}),u;if(E.getRaw)return p;switch(p.headers.get("Content-Type")?.split(";")[0]){case"application/json":u=await p.json();break;default:u=await p.text().then(L)}let f=p.status>=300||p.status<200?new R(p.status,u):null,d={data:u,error:f,response:p,status:p.status,headers:p.headers};if(x)for(let l of x){let v=l(d);v instanceof Promise&&(v=await v),v!=null&&(d=v)}return d})({getRaw:T})}}),ee=(e,t={fetcher:fetch})=>new Proxy({},{get(n,r){return Y(e,r,t)}});var we=async e=>{switch(e.headers.get("Content-Type")?.split(";")[0]){case"application/json":return e.json();case"application/octet-stream":return e.arrayBuffer();case"multipart/form-data":{let n=await e.formData(),r={};return n.forEach((a,s)=>{r[s]=a}),r}}return e.text().then(L)},be=async(e,t)=>{let n=await we(e);return e.status>300?{data:null,status:e.status,headers:e.headers,retry:t,error:new R(e.status,n)}:{data:n,error:null,status:e.status,headers:e.headers,retry:t}},te=(e,t)=>(n,{query:r,params:a,body:s,...i}={})=>{a&&Object.entries(a).forEach(([S,h])=>{n=n.replace(`:${S}`,h)});let y=t?.fetcher||globalThis.fetch,j=r?Object.fromEntries(Object.entries(r).filter(([S,h])=>h!=null)):null,A=j?`?${new URLSearchParams(j).toString()}`:"",w=`${e}${n}${A}`,k=new Headers(i.headers||{}),T=k.get("content-type");if(!(s instanceof FormData)&&!(s instanceof URLSearchParams)&&(!T||T==="application/json"))try{s=JSON.stringify(s),T||k.set("content-type","application/json")}catch{}let m={...i,method:i.method?.toUpperCase()||"GET",headers:k,body:s},b=()=>y(w,m).then(S=>be(S,b));return b()};0&&(module.exports={edenFetch,edenTreaty,treaty});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as r}from"./chunk-EF6Z4LSD.mjs";import{b as e}from"./chunk-
|
|
1
|
+
import{b as r}from"./chunk-EF6Z4LSD.mjs";import{b as e}from"./chunk-LJDYVDXQ.mjs";import{a as t}from"./chunk-4RPCKTWO.mjs";import"./chunk-QSLHAOSM.mjs";export{t as edenFetch,r as edenTreaty,e as treaty};
|
package/dist/treaty2.global.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var Eden=(()=>{var j=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var $=(e,t)=>{for(var n in t)j(e,n,{get:t[n],enumerable:!0})},B=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of U(t))!V.call(e,o)&&o!==n&&j(e,o,{get:()=>t[o],enumerable:!(s=H(t,o))||s.enumerable});return e};var Z=e=>B(j({},"__esModule",{value:!0}),e);var ie={};$(ie,{streamResponse:()=>
|
|
1
|
+
"use strict";var Eden=(()=>{var j=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var $=(e,t)=>{for(var n in t)j(e,n,{get:t[n],enumerable:!0})},B=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of U(t))!V.call(e,o)&&o!==n&&j(e,o,{get:()=>t[o],enumerable:!(s=H(t,o))||s.enumerable});return e};var Z=e=>B(j({},"__esModule",{value:!0}),e);var ie={};$(ie,{streamResponse:()=>J,treaty:()=>re});var k=class extends Error{constructor(n,s){super(s+"");this.status=n;this.value=s}};var G=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,z=/(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT(?:\+|-)\d{4}\s\([^)]+\)/,Q=/^(?:(?:(?:(?:0?[1-9]|[12][0-9]|3[01])[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:19|20)\d{2})|(?:(?:19|20)\d{2}[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:0?[1-9]|[12][0-9]|3[01]))))(?:\s(?:1[012]|0?[1-9]):[0-5][0-9](?::[0-5][0-9])?(?:\s[AP]M)?)?$/,X=e=>e.trim().length!==0&&!Number.isNaN(Number(e)),F=e=>{if(typeof e!="string")return null;let t=e.replace(/"/g,"");if(G.test(t)||z.test(t)||Q.test(t)){let n=new Date(t);if(!Number.isNaN(n.getTime()))return n}return null},Y=e=>{let t=e.charCodeAt(0),n=e.charCodeAt(e.length-1);return t===123&&n===125||t===91&&n===93},ee=e=>JSON.parse(e,(t,n)=>{let s=F(n);return s||n}),A=e=>{if(!e)return e;if(X(e))return+e;if(e==="true")return!0;if(e==="false")return!1;let t=F(e);if(t)return t;if(Y(e))try{return ee(e)}catch{}return e},D=e=>{let t=e.data.toString();return t==="null"?null:A(t)};var M=class{constructor(t){this.url=t;this.ws=new WebSocket(t)}ws;send(t){return Array.isArray(t)?(t.forEach(n=>this.send(n)),this):(this.ws.send(typeof t=="object"?JSON.stringify(t):t.toString()),this)}on(t,n,s){return this.addEventListener(t,n,s)}off(t,n,s){return this.ws.removeEventListener(t,n,s),this}subscribe(t,n){return this.addEventListener("message",t,n)}addEventListener(t,n,s){return this.ws.addEventListener(t,o=>{if(t==="message"){let c=D(o);n({...o,data:c})}else n(o)},s),this}removeEventListener(t,n,s){return this.off(t,n,s),this}close(){return this.ws.close(),this}};var te=["get","post","put","delete","patch","options","head","connect","subscribe"],I=["localhost","127.0.0.1","0.0.0.0"],C=typeof FileList>"u",q=e=>C?e instanceof Blob:e instanceof FileList||e instanceof File,ne=e=>{if(!e)return!1;for(let t in e)if(q(e[t])||Array.isArray(e[t])&&e[t].find(q))return!0;return!1},N=e=>C?e:new Promise(t=>{let n=new FileReader;n.onload=()=>{let s=new File([n.result],e.name,{lastModified:e.lastModified,type:e.type});t(s)},n.readAsArrayBuffer(e)}),S=(e,t,n={},s={})=>{if(Array.isArray(e)){for(let o of e)if(!Array.isArray(o))s=S(o,t,n,s);else{let c=o[0];if(typeof c=="string")s[c.toLowerCase()]=o[1];else for(let[i,g]of c)s[i.toLowerCase()]=g}return s}if(!e)return s;switch(typeof e){case"function":if(e instanceof Headers)return S(e,t,n,s);let o=e(t,n);return o?S(o,t,n,s):s;case"object":if(e instanceof Headers)return e.forEach((c,i)=>{s[i.toLowerCase()]=c}),s;for(let[c,i]of Object.entries(e))s[c.toLowerCase()]=i;return s;default:return s}};async function*J(e){let t=e.body;if(!t)return;let n=t.getReader(),s=new TextDecoder;try{for(;;){let{done:o,value:c}=await n.read();if(o)break;let i=typeof c=="string"?c:s.decode(c);i.includes(`
|
|
2
2
|
|
|
3
|
-
`)?yield*se(i):yield
|
|
3
|
+
`)?yield*se(i):yield A(i)}}finally{n.releaseLock()}}function*se(e){let t=e.split(`
|
|
4
4
|
|
|
5
|
-
`);for(let n of t){if(n.indexOf(":")<=0){n&&(yield
|
|
6
|
-
`),o={};for(let c of s){let i=c.indexOf(":");if(i>0){let g=c.slice(0,i).trim(),
|
|
5
|
+
`);for(let n of t){if(n.indexOf(":")<=0){n&&(yield A(n));continue}let s=n.split(`
|
|
6
|
+
`),o={};for(let c of s){let i=c.indexOf(":");if(i>0){let g=c.slice(0,i).trim(),L=c.slice(i+1).trim();o[g]=A(L)}}yield o}}var O=(e,t,n=[],s)=>new Proxy(()=>{},{get(o,c){return O(e,t,c==="index"?n:[...n,c],s)},apply(o,c,[i,g]){if(!i||g||typeof i=="object"&&Object.keys(i).length!==1||te.includes(n.at(-1))){let L=[...n],E=L.pop(),m="/"+L.join("/"),{fetcher:P=fetch,headers:R,onRequest:h,onResponse:v,fetch:_}=t,w=E==="get"||E==="head"||E==="subscribe";R=S(R,m,g);let K=w?i?.query:g?.query,T="";if(K){let r=(b,l)=>{T+=(T?"&":"?")+`${encodeURIComponent(b)}=${encodeURIComponent(l)}`};for(let[b,l]of Object.entries(K)){if(Array.isArray(l)){for(let d of l)r(b,d);continue}if(l!=null){if(typeof l=="object"){r(b,JSON.stringify(l));continue}r(b,`${l}`)}}}if(E==="subscribe"){let r=e.replace(/^([^]+):\/\//,e.startsWith("https://")?"wss://":e.startsWith("http://")||I.find(b=>e.includes(b))?"ws://":"wss://")+m+T;return new M(r)}return(async()=>{let r={method:E?.toUpperCase(),body:i,..._,headers:R};r.headers={...R,...S(w?i?.headers:g?.headers,m,r)};let b=w&&typeof i=="object"?i.fetch:g?.fetch;if(r={...r,...b},w&&delete r.body,h){Array.isArray(h)||(h=[h]);for(let u of h){let a=await u(m,r);typeof a=="object"&&(r={...r,...a,headers:{...r.headers,...S(a.headers,m,r)}})}}if(w&&delete r.body,ne(i)){let u=new FormData;for(let[a,f]of Object.entries(r.body)){if(Array.isArray(f)){for(let p=0;p<f.length;p++){let W=f[p];u.append(a,W instanceof File?await N(W):W)}continue}if(C){if(Array.isArray(f))for(let p of f)u.append(a,p);else u.append(a,f);continue}if(f instanceof File){u.append(a,await N(f));continue}if(f instanceof FileList){for(let p=0;p<f.length;p++)u.append(a,await N(f[p]));continue}u.append(a,f)}r.body=u}else typeof i=="object"?(r.headers["content-type"]="application/json",r.body=JSON.stringify(i)):i!=null&&(r.headers["content-type"]="text/plain");if(w&&delete r.body,h){Array.isArray(h)||(h=[h]);for(let u of h){let a=await u(m,r);typeof a=="object"&&(r={...r,...a,headers:{...r.headers,...S(a.headers,m,r)}})}}g?.headers?.["content-type"]&&(r.headers["content-type"]=g?.headers["content-type"]);let l=e+m+T,d=await(s?.handle(new Request(l,r))??P(l,r)),y=null,x=null;if(v){Array.isArray(v)||(v=[v]);for(let u of v)try{let a=await u(d.clone());if(a!=null){y=a;break}}catch(a){a instanceof k?x=a:x=new k(422,a);break}}if(y!==null)return{data:y,error:x,response:d,status:d.status,headers:d.headers};switch(d.headers.get("Content-Type")?.split(";")[0]){case"text/event-stream":y=J(d);break;case"application/json":y=JSON.parse(await d.text(),(a,f)=>{if(typeof f!="string")return f;let p=F(f);return p||f});break;case"application/octet-stream":y=await d.arrayBuffer();break;case"multipart/form-data":let u=await d.formData();y={},u.forEach((a,f)=>{y[f]=a});break;default:y=await d.text().then(A)}return(d.status>=300||d.status<200)&&(x=new k(d.status,y),y=null),{data:y,error:x,response:d,status:d.status,headers:d.headers}})()}return typeof i=="object"?O(e,t,[...n,Object.values(i)[0]],s):O(e,t,n)}}),re=(e,t={})=>typeof e=="string"?(t.keepDomain||(e.includes("://")||(e=(I.find(n=>e.includes(n))?"http://":"https://")+e),e.endsWith("/")&&(e=e.slice(0,-1))),O(e,t)):(typeof window<"u"&&console.warn("Elysia instance server found on client side, this is not recommended for security reason. Use generic type instead."),O("http://e.ly",t,[],e));return Z(ie);})();
|
package/dist/treaty2.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var j=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var $=(e,t)=>{for(var n in t)j(e,n,{get:t[n],enumerable:!0})},B=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of U(t))!V.call(e,o)&&o!==n&&j(e,o,{get:()=>t[o],enumerable:!(s=H(t,o))||s.enumerable});return e};var Z=e=>B(j({},"__esModule",{value:!0}),e);var ie={};$(ie,{streamResponse:()=>
|
|
1
|
+
"use strict";var j=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var $=(e,t)=>{for(var n in t)j(e,n,{get:t[n],enumerable:!0})},B=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of U(t))!V.call(e,o)&&o!==n&&j(e,o,{get:()=>t[o],enumerable:!(s=H(t,o))||s.enumerable});return e};var Z=e=>B(j({},"__esModule",{value:!0}),e);var ie={};$(ie,{streamResponse:()=>J,treaty:()=>re});module.exports=Z(ie);var k=class extends Error{constructor(n,s){super(s+"");this.status=n;this.value=s}};var G=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,z=/(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT(?:\+|-)\d{4}\s\([^)]+\)/,Q=/^(?:(?:(?:(?:0?[1-9]|[12][0-9]|3[01])[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:19|20)\d{2})|(?:(?:19|20)\d{2}[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:0?[1-9]|[12][0-9]|3[01]))))(?:\s(?:1[012]|0?[1-9]):[0-5][0-9](?::[0-5][0-9])?(?:\s[AP]M)?)?$/,X=e=>e.trim().length!==0&&!Number.isNaN(Number(e)),F=e=>{if(typeof e!="string")return null;let t=e.replace(/"/g,"");if(G.test(t)||z.test(t)||Q.test(t)){let n=new Date(t);if(!Number.isNaN(n.getTime()))return n}return null},Y=e=>{let t=e.charCodeAt(0),n=e.charCodeAt(e.length-1);return t===123&&n===125||t===91&&n===93},ee=e=>JSON.parse(e,(t,n)=>{let s=F(n);return s||n}),A=e=>{if(!e)return e;if(X(e))return+e;if(e==="true")return!0;if(e==="false")return!1;let t=F(e);if(t)return t;if(Y(e))try{return ee(e)}catch{}return e},D=e=>{let t=e.data.toString();return t==="null"?null:A(t)};var M=class{constructor(t){this.url=t;this.ws=new WebSocket(t)}ws;send(t){return Array.isArray(t)?(t.forEach(n=>this.send(n)),this):(this.ws.send(typeof t=="object"?JSON.stringify(t):t.toString()),this)}on(t,n,s){return this.addEventListener(t,n,s)}off(t,n,s){return this.ws.removeEventListener(t,n,s),this}subscribe(t,n){return this.addEventListener("message",t,n)}addEventListener(t,n,s){return this.ws.addEventListener(t,o=>{if(t==="message"){let c=D(o);n({...o,data:c})}else n(o)},s),this}removeEventListener(t,n,s){return this.off(t,n,s),this}close(){return this.ws.close(),this}};var te=["get","post","put","delete","patch","options","head","connect","subscribe"],I=["localhost","127.0.0.1","0.0.0.0"],C=typeof FileList>"u",q=e=>C?e instanceof Blob:e instanceof FileList||e instanceof File,ne=e=>{if(!e)return!1;for(let t in e)if(q(e[t])||Array.isArray(e[t])&&e[t].find(q))return!0;return!1},N=e=>C?e:new Promise(t=>{let n=new FileReader;n.onload=()=>{let s=new File([n.result],e.name,{lastModified:e.lastModified,type:e.type});t(s)},n.readAsArrayBuffer(e)}),S=(e,t,n={},s={})=>{if(Array.isArray(e)){for(let o of e)if(!Array.isArray(o))s=S(o,t,n,s);else{let c=o[0];if(typeof c=="string")s[c.toLowerCase()]=o[1];else for(let[i,g]of c)s[i.toLowerCase()]=g}return s}if(!e)return s;switch(typeof e){case"function":if(e instanceof Headers)return S(e,t,n,s);let o=e(t,n);return o?S(o,t,n,s):s;case"object":if(e instanceof Headers)return e.forEach((c,i)=>{s[i.toLowerCase()]=c}),s;for(let[c,i]of Object.entries(e))s[c.toLowerCase()]=i;return s;default:return s}};async function*J(e){let t=e.body;if(!t)return;let n=t.getReader(),s=new TextDecoder;try{for(;;){let{done:o,value:c}=await n.read();if(o)break;let i=typeof c=="string"?c:s.decode(c);i.includes(`
|
|
2
2
|
|
|
3
|
-
`)?yield*se(i):yield
|
|
3
|
+
`)?yield*se(i):yield A(i)}}finally{n.releaseLock()}}function*se(e){let t=e.split(`
|
|
4
4
|
|
|
5
|
-
`);for(let n of t){if(n.indexOf(":")<=0){n&&(yield
|
|
6
|
-
`),o={};for(let c of s){let i=c.indexOf(":");if(i>0){let g=c.slice(0,i).trim(),
|
|
5
|
+
`);for(let n of t){if(n.indexOf(":")<=0){n&&(yield A(n));continue}let s=n.split(`
|
|
6
|
+
`),o={};for(let c of s){let i=c.indexOf(":");if(i>0){let g=c.slice(0,i).trim(),L=c.slice(i+1).trim();o[g]=A(L)}}yield o}}var O=(e,t,n=[],s)=>new Proxy(()=>{},{get(o,c){return O(e,t,c==="index"?n:[...n,c],s)},apply(o,c,[i,g]){if(!i||g||typeof i=="object"&&Object.keys(i).length!==1||te.includes(n.at(-1))){let L=[...n],E=L.pop(),m="/"+L.join("/"),{fetcher:P=fetch,headers:R,onRequest:h,onResponse:v,fetch:_}=t,w=E==="get"||E==="head"||E==="subscribe";R=S(R,m,g);let K=w?i?.query:g?.query,T="";if(K){let r=(b,l)=>{T+=(T?"&":"?")+`${encodeURIComponent(b)}=${encodeURIComponent(l)}`};for(let[b,l]of Object.entries(K)){if(Array.isArray(l)){for(let d of l)r(b,d);continue}if(l!=null){if(typeof l=="object"){r(b,JSON.stringify(l));continue}r(b,`${l}`)}}}if(E==="subscribe"){let r=e.replace(/^([^]+):\/\//,e.startsWith("https://")?"wss://":e.startsWith("http://")||I.find(b=>e.includes(b))?"ws://":"wss://")+m+T;return new M(r)}return(async()=>{let r={method:E?.toUpperCase(),body:i,..._,headers:R};r.headers={...R,...S(w?i?.headers:g?.headers,m,r)};let b=w&&typeof i=="object"?i.fetch:g?.fetch;if(r={...r,...b},w&&delete r.body,h){Array.isArray(h)||(h=[h]);for(let u of h){let a=await u(m,r);typeof a=="object"&&(r={...r,...a,headers:{...r.headers,...S(a.headers,m,r)}})}}if(w&&delete r.body,ne(i)){let u=new FormData;for(let[a,f]of Object.entries(r.body)){if(Array.isArray(f)){for(let p=0;p<f.length;p++){let W=f[p];u.append(a,W instanceof File?await N(W):W)}continue}if(C){if(Array.isArray(f))for(let p of f)u.append(a,p);else u.append(a,f);continue}if(f instanceof File){u.append(a,await N(f));continue}if(f instanceof FileList){for(let p=0;p<f.length;p++)u.append(a,await N(f[p]));continue}u.append(a,f)}r.body=u}else typeof i=="object"?(r.headers["content-type"]="application/json",r.body=JSON.stringify(i)):i!=null&&(r.headers["content-type"]="text/plain");if(w&&delete r.body,h){Array.isArray(h)||(h=[h]);for(let u of h){let a=await u(m,r);typeof a=="object"&&(r={...r,...a,headers:{...r.headers,...S(a.headers,m,r)}})}}g?.headers?.["content-type"]&&(r.headers["content-type"]=g?.headers["content-type"]);let l=e+m+T,d=await(s?.handle(new Request(l,r))??P(l,r)),y=null,x=null;if(v){Array.isArray(v)||(v=[v]);for(let u of v)try{let a=await u(d.clone());if(a!=null){y=a;break}}catch(a){a instanceof k?x=a:x=new k(422,a);break}}if(y!==null)return{data:y,error:x,response:d,status:d.status,headers:d.headers};switch(d.headers.get("Content-Type")?.split(";")[0]){case"text/event-stream":y=J(d);break;case"application/json":y=JSON.parse(await d.text(),(a,f)=>{if(typeof f!="string")return f;let p=F(f);return p||f});break;case"application/octet-stream":y=await d.arrayBuffer();break;case"multipart/form-data":let u=await d.formData();y={},u.forEach((a,f)=>{y[f]=a});break;default:y=await d.text().then(A)}return(d.status>=300||d.status<200)&&(x=new k(d.status,y),y=null),{data:y,error:x,response:d,status:d.status,headers:d.headers}})()}return typeof i=="object"?O(e,t,[...n,Object.values(i)[0]],s):O(e,t,n)}}),re=(e,t={})=>typeof e=="string"?(t.keepDomain||(e.includes("://")||(e=(I.find(n=>e.includes(n))?"http://":"https://")+e),e.endsWith("/")&&(e=e.slice(0,-1))),O(e,t)):(typeof window<"u"&&console.warn("Elysia instance server found on client side, this is not recommended for security reason. Use generic type instead."),O("http://e.ly",t,[],e));0&&(module.exports={streamResponse,treaty});
|
package/dist/treaty2.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b}from"./chunk-
|
|
1
|
+
import{a,b}from"./chunk-LJDYVDXQ.mjs";import"./chunk-QSLHAOSM.mjs";export{a as streamResponse,b as treaty};
|
package/package.json
CHANGED
package/dist/chunk-ZIS6B6IO.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{a as W,b as M,c as A,d as q}from"./chunk-QSLHAOSM.mjs";var F=class{constructor(t){this.url=t;this.ws=new WebSocket(t)}ws;send(t){return Array.isArray(t)?(t.forEach(n=>this.send(n)),this):(this.ws.send(typeof t=="object"?JSON.stringify(t):t.toString()),this)}on(t,n,s){return this.addEventListener(t,n,s)}off(t,n,s){return this.ws.removeEventListener(t,n,s),this}subscribe(t,n){return this.addEventListener("message",t,n)}addEventListener(t,n,s){return this.ws.addEventListener(t,l=>{if(t==="message"){let o=q(l);n({...l,data:o})}else n(l)},s),this}removeEventListener(t,n,s){return this.off(t,n,s),this}close(){return this.ws.close(),this}};var P=["get","post","put","delete","patch","options","head","connect","subscribe"],N=["localhost","127.0.0.1","0.0.0.0"],C=typeof FileList>"u",I=e=>C?e instanceof Blob:e instanceof FileList||e instanceof File,U=e=>{if(!e)return!1;for(let t in e)if(I(e[t])||Array.isArray(e[t])&&e[t].find(I))return!0;return!1},T=e=>C?e:new Promise(t=>{let n=new FileReader;n.onload=()=>{let s=new File([n.result],e.name,{lastModified:e.lastModified,type:e.type});t(s)},n.readAsArrayBuffer(e)}),b=(e,t,n={},s={})=>{if(Array.isArray(e)){for(let l of e)if(!Array.isArray(l))s=b(l,t,n,s);else{let o=l[0];if(typeof o=="string")s[o.toLowerCase()]=l[1];else for(let[i,h]of o)s[i.toLowerCase()]=h}return s}if(!e)return s;switch(typeof e){case"function":if(e instanceof Headers)return b(e,t,n,s);let l=e(t,n);return l?b(l,t,n,s):s;case"object":if(e instanceof Headers)return e.forEach((o,i)=>{s[i.toLowerCase()]=o}),s;for(let[o,i]of Object.entries(e))s[o.toLowerCase()]=i;return s;default:return s}};async function*D(e){let t=e.body;if(!t)return;let n=t.getReader(),s=new TextDecoder;try{for(;;){let{done:l,value:o}=await n.read();if(l)break;let i=typeof o=="string"?o:s.decode(o);i.includes(`
|
|
2
|
-
|
|
3
|
-
`)?yield*_(i):yield A(i)}}finally{n.releaseLock()}}function*_(e){let t=e.split(`
|
|
4
|
-
|
|
5
|
-
`);for(let n of t){if(n.indexOf(":")<=0){n&&(yield A(n));continue}let s=n.split(`
|
|
6
|
-
`),l={};for(let o of s){let i=o.indexOf(":");if(i>0){let h=o.slice(0,i).trim(),L=o.slice(i+1).trim();l[h]=A(L)}}yield l}}var x=(e,t,n=[],s)=>new Proxy(()=>{},{get(l,o){return x(e,t,o==="index"?n:[...n,o],s)},apply(l,o,[i,h]){if(!i||h||typeof i=="object"&&Object.keys(i).length!==1||P.includes(n.at(-1))){let L=[...n],k=L.pop(),v="/"+L.join("/"),{fetcher:H=fetch,headers:R,onRequest:g,onResponse:E,fetch:J}=t,m=k==="get"||k==="head"||k==="subscribe";R=b(R,v,h);let K=m?i?.query:h?.query,O="";if(K){let r=(w,d)=>{O+=(O?"&":"?")+`${encodeURIComponent(w)}=${encodeURIComponent(d)}`};for(let[w,d]of Object.entries(K)){if(Array.isArray(d)){for(let c of d)r(w,c);continue}if(d!=null){if(typeof d=="object"){r(w,JSON.stringify(d));continue}r(w,`${d}`)}}}if(k==="subscribe"){let r=e.replace(/^([^]+):\/\//,e.startsWith("https://")?"wss://":e.startsWith("http://")||N.find(w=>e.includes(w))?"ws://":"wss://")+v+O;return new F(r)}return(async()=>{let r={method:k?.toUpperCase(),body:i,...J,headers:R};r.headers={...R,...b(m?i?.headers:h?.headers,v,r)};let w=m&&typeof i=="object"?i.fetch:h?.fetch;if(r={...r,...w},m&&delete r.body,g){Array.isArray(g)||(g=[g]);for(let y of g){let a=await y(v,r);typeof a=="object"&&(r={...r,...a,headers:{...r.headers,...b(a.headers,v,r)}})}}if(m&&delete r.body,U(i)){let y=new FormData;for(let[a,f]of Object.entries(r.body)){if(Array.isArray(f)){for(let p=0;p<f.length;p++){let j=f[p];y.append(a,j instanceof File?await T(j):j)}continue}if(C){if(Array.isArray(f))for(let p of f)y.append(a,p);else y.append(a,f);continue}if(f instanceof File){y.append(a,await T(f));continue}if(f instanceof FileList){for(let p=0;p<f.length;p++)y.append(a,await T(f[p]));continue}y.append(a,f)}r.body=y}else typeof i=="object"?(r.headers["content-type"]="application/json",r.body=JSON.stringify(i)):i!=null&&(r.headers["content-type"]="text/plain");if(m&&delete r.body,g){Array.isArray(g)||(g=[g]);for(let y of g){let a=await y(v,r);typeof a=="object"&&(r={...r,...a,headers:{...r.headers,...b(a.headers,v,r)}})}}h?.headers?.["content-type"]&&(r.headers["content-type"]=h?.headers["content-type"]);let d=e+v+O,c=await(s?.handle(new Request(d,r))??H(d,r)),u=null,S=null;if(E){Array.isArray(E)||(E=[E]);for(let y of E)try{let a=await y(c.clone());if(a!=null){u=a;break}}catch(a){a instanceof W?S=a:S=new W(422,a);break}}if(u!==null)return{data:u,error:S,response:c,status:c.status,headers:c.headers};if(c.headers.get("Transfer-Encoding")==="chunked")u=D(c);else switch(c.headers.get("Content-Type")?.split(";")[0]){case"text/event-stream":u=D(c);break;case"application/json":u=JSON.parse(await c.text(),(a,f)=>{if(typeof f!="string")return f;let p=M(f);return p||f});break;case"application/octet-stream":u=await c.arrayBuffer();break;case"multipart/form-data":let y=await c.formData();u={},y.forEach((a,f)=>{u[f]=a});break;default:u=await c.text().then(A)}return(c.status>=300||c.status<200)&&(S=new W(c.status,u),u=null),{data:u,error:S,response:c,status:c.status,headers:c.headers}})()}return typeof i=="object"?x(e,t,[...n,Object.values(i)[0]],s):x(e,t,n)}}),Q=(e,t={})=>typeof e=="string"?(t.keepDomain||(e.includes("://")||(e=(N.find(n=>e.includes(n))?"http://":"https://")+e),e.endsWith("/")&&(e=e.slice(0,-1))),x(e,t)):(typeof window<"u"&&console.warn("Elysia instance server found on client side, this is not recommended for security reason. Use generic type instead."),x("http://e.ly",t,[],e));export{D as a,Q as b};
|