@elysiajs/eden 0.2.0-rc.4 → 0.2.0-rc.5
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/index.js +1 -1
- package/dist/index.mjs +18 -14
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +11 -2
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class y{constructor(e){this.ws=new WebSocket(e),this.url=e}send(e){return Array.isArray(e)?(e.forEach(t=>this.send(t)),this):(this.ws.send(typeof e=="object"?JSON.stringify(e):e.toString()),this)}on(e,t,s){return this.addEventListener(e,t,s)}off(e,t,s){return this.ws.removeEventListener(e,t,s),this}addEventListener(e,t,s){return this.ws.addEventListener(e,i=>{if(e==="message"){let r=i.data.toString();const l=r.charCodeAt(0);if(l===47||l===123)try{r=JSON.parse(r)}catch{}else Number.isNaN(+r)?r==="true"?r=!0:r==="fase"&&(r=!1):r=+r;t({...i,data:r})}else t(i)},s),this}removeEventListener(e,t,s){return this.off(e,t,s),this}close(){return this.ws.close(),this}}const w=n=>n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),p=(n,e,t)=>{if(n.endsWith("/")||(n+="/"),e=w(e.replace(/index/g,"")),!t||!Object.keys(t).length)return`${n}${e}`;let s="";for(const[i,r]of Object.entries(t))s+=`${i}=${r}&`;return`${n}${e}?${s.slice(0,-1)}`},v=(n,e="")=>new Proxy(()=>{},{get(t,s,i){return v(n,`${e}/${s.toString()}`)},apply(t,s,[{$query:i,$fetch:r,$body:l,...u}={$fetch:void 0,$query:void 0,$body:void 0}]=[{}]){const h=e.lastIndexOf("/"),d=e.slice(h+1),f=p(n,e.slice(0,h),i);if(d==="subscribe")return new y(f.replace(/^([^]+):\/\//,f.startsWith("https://")?"wss://":"ws://"));const o=l??(Object.keys(u).length?u:void 0);return fetch(f,{method:d,body:JSON.stringify(o),headers:o?{"content-type":typeof u=="object"?"application/json":"text/plain","content-length":o==null?void 0:o.length,...r==null?void 0:r.headers}:void 0,...r}).then(async c=>{var g;if(c.status>=300)throw new Error(await c.text());if((g=c.headers.get("content-type"))!=null&&g.includes("application/json"))try{return c.json()}catch{}const a=await c.text();return Number.isNaN(+a)?a==="true"?!0:a==="false"?!1:a:+a})}}),S=n=>new Proxy({},{get(e,t,s){return v(n,t)}});exports.EdenWS=y;exports.eden=S;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class y {
|
|
2
2
|
constructor(e) {
|
|
3
3
|
this.ws = new WebSocket(e), this.url = e;
|
|
4
4
|
}
|
|
@@ -44,17 +44,17 @@ class v {
|
|
|
44
44
|
return this.ws.close(), this;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
const w = (n) => n.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`),
|
|
47
|
+
const w = (n) => n.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`), p = (n, e, t) => {
|
|
48
48
|
if (n.endsWith("/") || (n += "/"), e = w(e.replace(/index/g, "")), !t || !Object.keys(t).length)
|
|
49
49
|
return `${n}${e}`;
|
|
50
50
|
let s = "";
|
|
51
51
|
for (const [i, r] of Object.entries(t))
|
|
52
52
|
s += `${i}=${r}&`;
|
|
53
53
|
return `${n}${e}?${s.slice(0, -1)}`;
|
|
54
|
-
},
|
|
54
|
+
}, v = (n, e = "") => new Proxy(() => {
|
|
55
55
|
}, {
|
|
56
56
|
get(t, s, i) {
|
|
57
|
-
return
|
|
57
|
+
return v(n, `${e}/${s.toString()}`);
|
|
58
58
|
},
|
|
59
59
|
apply(t, s, [
|
|
60
60
|
{ $query: i, $fetch: r, $body: l, ...u } = {
|
|
@@ -63,9 +63,9 @@ const w = (n) => n.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`), y = (n, e, t
|
|
|
63
63
|
$body: void 0
|
|
64
64
|
}
|
|
65
65
|
] = [{}]) {
|
|
66
|
-
const h = e.lastIndexOf("/"),
|
|
67
|
-
if (
|
|
68
|
-
return new
|
|
66
|
+
const h = e.lastIndexOf("/"), d = e.slice(h + 1), f = p(n, e.slice(0, h), i);
|
|
67
|
+
if (d === "subscribe")
|
|
68
|
+
return new y(
|
|
69
69
|
f.replace(
|
|
70
70
|
/^([^]+):\/\//,
|
|
71
71
|
f.startsWith("https://") ? "wss://" : "ws://"
|
|
@@ -73,7 +73,7 @@ const w = (n) => n.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`), y = (n, e, t
|
|
|
73
73
|
);
|
|
74
74
|
const o = l ?? (Object.keys(u).length ? u : void 0);
|
|
75
75
|
return fetch(f, {
|
|
76
|
-
method:
|
|
76
|
+
method: d,
|
|
77
77
|
body: JSON.stringify(o),
|
|
78
78
|
headers: o ? {
|
|
79
79
|
"content-type": typeof u == "object" ? "application/json" : "text/plain",
|
|
@@ -82,23 +82,27 @@ const w = (n) => n.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`), y = (n, e, t
|
|
|
82
82
|
} : void 0,
|
|
83
83
|
...r
|
|
84
84
|
}).then(async (c) => {
|
|
85
|
+
var g;
|
|
85
86
|
if (c.status >= 300)
|
|
86
87
|
throw new Error(await c.text());
|
|
87
|
-
if (c.headers.get("content-type")
|
|
88
|
-
|
|
88
|
+
if ((g = c.headers.get("content-type")) != null && g.includes("application/json"))
|
|
89
|
+
try {
|
|
90
|
+
return c.json();
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
89
93
|
const a = await c.text();
|
|
90
94
|
return Number.isNaN(+a) ? a === "true" ? !0 : a === "false" ? !1 : a : +a;
|
|
91
95
|
});
|
|
92
96
|
}
|
|
93
|
-
}),
|
|
97
|
+
}), N = (n) => new Proxy(
|
|
94
98
|
{},
|
|
95
99
|
{
|
|
96
100
|
get(e, t, s) {
|
|
97
|
-
return
|
|
101
|
+
return v(n, t);
|
|
98
102
|
}
|
|
99
103
|
}
|
|
100
104
|
);
|
|
101
105
|
export {
|
|
102
|
-
|
|
103
|
-
|
|
106
|
+
y as EdenWS,
|
|
107
|
+
N as eden
|
|
104
108
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(o,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(o=typeof globalThis<"u"?globalThis:o||self,c(o["@elysia/eden"]={}))})(this,function(o){"use strict";class c{constructor(e){this.ws=new WebSocket(e),this.url=e}send(e){return Array.isArray(e)?(e.forEach(t=>this.send(t)),this):(this.ws.send(typeof e=="object"?JSON.stringify(e):e.toString()),this)}on(e,t,s){return this.addEventListener(e,t,s)}off(e,t,s){return this.ws.removeEventListener(e,t,s),this}addEventListener(e,t,s){return this.ws.addEventListener(e,i=>{if(e==="message"){let n=i.data.toString();const a=n.charCodeAt(0);if(a===47||a===123)try{n=JSON.parse(n)}catch{}else Number.isNaN(+n)?n==="true"?n=!0:n==="fase"&&(n=!1):n=+n;t({...i,data:n})}else t(i)},s),this}removeEventListener(e,t,s){return this.off(e,t,s),this}close(){return this.ws.close(),this}}const
|
|
1
|
+
(function(o,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(o=typeof globalThis<"u"?globalThis:o||self,c(o["@elysia/eden"]={}))})(this,function(o){"use strict";class c{constructor(e){this.ws=new WebSocket(e),this.url=e}send(e){return Array.isArray(e)?(e.forEach(t=>this.send(t)),this):(this.ws.send(typeof e=="object"?JSON.stringify(e):e.toString()),this)}on(e,t,s){return this.addEventListener(e,t,s)}off(e,t,s){return this.ws.removeEventListener(e,t,s),this}addEventListener(e,t,s){return this.ws.addEventListener(e,i=>{if(e==="message"){let n=i.data.toString();const a=n.charCodeAt(0);if(a===47||a===123)try{n=JSON.parse(n)}catch{}else Number.isNaN(+n)?n==="true"?n=!0:n==="fase"&&(n=!1):n=+n;t({...i,data:n})}else t(i)},s),this}removeEventListener(e,t,s){return this.off(e,t,s),this}close(){return this.ws.close(),this}}const w=r=>r.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),S=(r,e,t)=>{if(r.endsWith("/")||(r+="/"),e=w(e.replace(/index/g,"")),!t||!Object.keys(t).length)return`${r}${e}`;let s="";for(const[i,n]of Object.entries(t))s+=`${i}=${n}&`;return`${r}${e}?${s.slice(0,-1)}`},g=(r,e="")=>new Proxy(()=>{},{get(t,s,i){return g(r,`${e}/${s.toString()}`)},apply(t,s,[{$query:i,$fetch:n,$body:a,...d}={$fetch:void 0,$query:void 0,$body:void 0}]=[{}]){const y=e.lastIndexOf("/"),p=e.slice(y+1),h=S(r,e.slice(0,y),i);if(p==="subscribe")return new c(h.replace(/^([^]+):\/\//,h.startsWith("https://")?"wss://":"ws://"));const u=a??(Object.keys(d).length?d:void 0);return fetch(h,{method:p,body:JSON.stringify(u),headers:u?{"content-type":typeof d=="object"?"application/json":"text/plain","content-length":u==null?void 0:u.length,...n==null?void 0:n.headers}:void 0,...n}).then(async f=>{var v;if(f.status>=300)throw new Error(await f.text());if((v=f.headers.get("content-type"))!=null&&v.includes("application/json"))try{return f.json()}catch{}const l=await f.text();return Number.isNaN(+l)?l==="true"?!0:l==="false"?!1:l:+l})}}),b=r=>new Proxy({},{get(e,t,s){return g(r,t)}});o.EdenWS=c,o.eden=b,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -172,8 +172,17 @@ const createProxy = (
|
|
|
172
172
|
}).then(async (res) => {
|
|
173
173
|
if (res.status >= 300) throw new Error(await res.text())
|
|
174
174
|
|
|
175
|
-
if (
|
|
176
|
-
|
|
175
|
+
if (
|
|
176
|
+
res.headers
|
|
177
|
+
.get('content-type')
|
|
178
|
+
?.includes('application/json')
|
|
179
|
+
)
|
|
180
|
+
try {
|
|
181
|
+
return res.json()
|
|
182
|
+
} catch (_) {
|
|
183
|
+
// if json is error then it's string
|
|
184
|
+
// flow down
|
|
185
|
+
}
|
|
177
186
|
|
|
178
187
|
const result = await res.text()
|
|
179
188
|
|