@elysiajs/eden 0.2.0-rc.1 → 0.2.0-rc.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.
- package/dist/index.js +1 -1
- package/dist/index.mjs +12 -7
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +6 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class g{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 y=n=>n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),w=(n,e,t)=>{if(n.endsWith("/")||(n+="/"),e=y(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
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class g{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 y=n=>n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),w=(n,e,t)=>{if(n.endsWith("/")||(n+="/"),e=y(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=w(n,e.slice(0,h),i);if(d==="subscribe")return new g(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=>{if(c.status>=300)throw new Error(await c.text());if(c.headers.get("content-type")==="application/json")return c.json();const a=await c.text();return Number.isNaN(+a)?a==="true"?!0:a==="false"?!1:a:+a})}}),p=n=>new Proxy({},{get(e,t,s){return v(n,t)}});exports.EdenWS=g;exports.eden=p;
|
package/dist/index.mjs
CHANGED
|
@@ -44,8 +44,8 @@ class v {
|
|
|
44
44
|
return this.ws.close(), this;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
const
|
|
48
|
-
if (n.endsWith("/") || (n += "/"), e =
|
|
47
|
+
const w = (n) => n.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`), y = (n, e, t) => {
|
|
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))
|
|
@@ -63,12 +63,17 @@ const y = (n) => n.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`), w = (n, e, t
|
|
|
63
63
|
$body: void 0
|
|
64
64
|
}
|
|
65
65
|
] = [{}]) {
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
68
|
-
return new v(
|
|
66
|
+
const h = e.lastIndexOf("/"), g = e.slice(h + 1), f = y(n, e.slice(0, h), i);
|
|
67
|
+
if (g === "subscribe")
|
|
68
|
+
return new v(
|
|
69
|
+
f.replace(
|
|
70
|
+
/^([^]+):\/\//,
|
|
71
|
+
f.startsWith("https://") ? "wss://" : "ws://"
|
|
72
|
+
)
|
|
73
|
+
);
|
|
69
74
|
const o = l ?? (Object.keys(u).length ? u : void 0);
|
|
70
|
-
return fetch(
|
|
71
|
-
method:
|
|
75
|
+
return fetch(f, {
|
|
76
|
+
method: g,
|
|
72
77
|
body: JSON.stringify(o),
|
|
73
78
|
headers: o ? {
|
|
74
79
|
"content-type": typeof u == "object" ? "application/json" : "text/plain",
|
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,
|
|
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 v=r=>r.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),w=(r,e,t)=>{if(r.endsWith("/")||(r+="/"),e=v(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=w(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=>{if(f.status>=300)throw new Error(await f.text());if(f.headers.get("content-type")==="application/json")return f.json();const l=await f.text();return Number.isNaN(+l)?l==="true"?!0:l==="false"?!1:l:+l})}}),S=r=>new Proxy({},{get(e,t,s){return g(r,t)}});o.EdenWS=c,o.eden=S,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -145,7 +145,12 @@ const createProxy = (
|
|
|
145
145
|
url = composePath(domain, path.slice(0, i), $query)
|
|
146
146
|
|
|
147
147
|
if (method === 'subscribe')
|
|
148
|
-
return new EdenWS(
|
|
148
|
+
return new EdenWS(
|
|
149
|
+
url.replace(
|
|
150
|
+
/^([^]+):\/\//,
|
|
151
|
+
url.startsWith('https://') ? 'wss://' : 'ws://'
|
|
152
|
+
)
|
|
153
|
+
)
|
|
149
154
|
|
|
150
155
|
const body =
|
|
151
156
|
$body ?? (Object.keys(bodyObj).length ? bodyObj : undefined)
|