@elysiajs/eden 0.3.0-exp-230222.2125 → 0.3.0-exp-230222.2210
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 +19 -19
- package/dist/index.umd.js +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var O=Object.create;var E=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var z=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var J=(s,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of P(t))!F.call(s,r)&&r!==e&&E(s,r,{get:()=>t[r],enumerable:!(n=N(t,r))||n.enumerable});return s};var L=(s,t,e)=>(e=s!=null?O(z(s)):{},J(t||!s||!s.__esModule?E(e,"default",{value:s,enumerable:!0}):e,s));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class
|
|
1
|
+
"use strict";var O=Object.create;var E=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var z=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var J=(s,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of P(t))!F.call(s,r)&&r!==e&&E(s,r,{get:()=>t[r],enumerable:!(n=N(t,r))||n.enumerable});return s};var L=(s,t,e)=>(e=s!=null?O(z(s)):{},J(t||!s||!s.__esModule?E(e,"default",{value:s,enumerable:!0}):e,s));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class A extends Error{constructor(t,e){super(),this.status=t,this.value=e}}const W=s=>s.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`),m=(s,t,e)=>{if(s.endsWith("/")||(s+="/"),t=W(t.replace(/index/g,"")),!e||!Object.keys(e).length)return`${s}${t}`;let n="";for(const[r,i]of Object.entries(e))n+=`${r}=${i}&`;return`${s}${t}?${n.slice(0,-1)}`};class p{constructor(t,e){this.pendings=[],this.operation=null,this.isFetching=!1,this.url=t,this.config=e,this.sJson=import("superjson").then(n=>({serialize:n.serialize,deserialize:n.deserialize}))}setConfig(t){this.config=t}clone(t){return new p(this.url,t??this.config)}async run(t,e){var i;const n=+this.pendings.length;if(this.pendings.push(e!==void 0?{n:t,p:e}:{n:t}),this.isFetching)return(i=this.operation)==null?void 0:i.then(o=>o[n]);this.isFetching=!0,this.operation=new Promise(o=>{setTimeout(async()=>{var l;const a=[...this.pendings];this.pendings=[];const{serialize:g,deserialize:y}=await this.sJson,h=await fetch(`${this.url}${this.config.fn??"/~fn"}`,{method:"POST",...this.config.fetch,headers:{"content-type":"elysia/fn",...(l=this.config.fetch)==null?void 0:l.headers},body:JSON.stringify(g(a))});h.status===200?o(h.json().then(u=>y(u))):o(Array(a.length).fill(new Error(await h.text())))},33)});const r=await this.operation.then(o=>o[n]);return this.operation=null,this.isFetching=!1,r}}class ${constructor(t){this.ws=new WebSocket(t),this.url=t}send(t){return Array.isArray(t)?(t.forEach(e=>this.send(e)),this):(this.ws.send(typeof t=="object"?JSON.stringify(t):t.toString()),this)}on(t,e,n){return this.addEventListener(t,e,n)}off(t,e,n){return this.ws.removeEventListener(t,e,n),this}addEventListener(t,e,n){return this.ws.addEventListener(t,r=>{if(t==="message"){let i=r.data.toString();const o=i.charCodeAt(0);if(o===47||o===123)try{i=JSON.parse(i)}catch{}else Number.isNaN(+i)?i==="true"?i=!0:i==="fase"&&(i=!1):i=+i;e({...r,data:i})}else e(r)},n),this}removeEventListener(t,e,n){return this.off(t,e,n),this}close(){return this.ws.close(),this}}const w=(s,t,e)=>new Proxy((...n)=>{},{get(n,r,i){return w(s,[...t,r],e)},apply(n,r,i){const o=i[0];if(t.length===1){if(t[0]in Object.prototype||t[0]in Promise.prototype)return n(i);switch(t[0]){case"toJSON":return n(i);case"$set":return e.setConfig(o);case"$clone":return w(s,[],e.clone(o))}}return e.run(t,i).then(a=>{if(a instanceof Error)throw a;return a})}}),x=(s,t="",e)=>new Proxy(()=>{},{get(n,r,i){return x(s,`${t}/${r.toString()}`,e)},apply(n,r,[{$query:i,$fetch:o,$body:a,...g}={$fetch:void 0,$query:void 0,$body:void 0}]=[{}]){var b;const y=t.lastIndexOf("/"),h=t.slice(y+1),l=m(s,t.slice(0,y),i);if(h==="subscribe")return new $(l.replace(/^([^]+):\/\//,l.startsWith("https://")?"wss://":"ws://"));const u=a??(Object.keys(g).length?g:void 0),v=typeof u=="object";return fetch(l,{method:h,body:v?JSON.stringify(u):u,...e.fetch,...o,headers:u?{"content-type":v?"application/json":"text/plain",...(b=e.fetch)==null?void 0:b.headers,...o==null?void 0:o.headers}:void 0}).then(async c=>{var S,j;if(c.status>300){let d;if((S=c.headers.get("content-type"))!=null&&S.includes("application/json"))try{d=await c.json()}catch{d=await c.text()}else d=await c.text();return new A(c.status,d)}if((j=c.headers.get("content-type"))!=null&&j.includes("application/json"))try{return await c.json()}catch{}let f=await c.text();return Number.isNaN(+f)?f==="true"?!0:f==="false"?!1:f:+f})}}),C=(s,t={})=>new Proxy({},{get(e,n){return n==="$fn"?w(s,[],new p(s,t)):x(s,n,t)}});exports.EdenWS=$;exports.eden=C;
|
package/dist/index.mjs
CHANGED
|
@@ -34,7 +34,7 @@ class p {
|
|
|
34
34
|
this.isFetching = !0, this.operation = new Promise((r) => {
|
|
35
35
|
setTimeout(async () => {
|
|
36
36
|
var l;
|
|
37
|
-
const
|
|
37
|
+
const a = [...this.pendings];
|
|
38
38
|
this.pendings = [];
|
|
39
39
|
const { serialize: d, deserialize: y } = await this.sJson, h = await fetch(
|
|
40
40
|
`${this.url}${this.config.fn ?? "/~fn"}`,
|
|
@@ -45,11 +45,11 @@ class p {
|
|
|
45
45
|
"content-type": "elysia/fn",
|
|
46
46
|
...(l = this.config.fetch) == null ? void 0 : l.headers
|
|
47
47
|
},
|
|
48
|
-
body: JSON.stringify(d(
|
|
48
|
+
body: JSON.stringify(d(a))
|
|
49
49
|
}
|
|
50
50
|
);
|
|
51
51
|
h.status === 200 ? r(h.json().then((u) => y(u))) : r(
|
|
52
|
-
Array(
|
|
52
|
+
Array(a.length).fill(
|
|
53
53
|
new Error(await h.text())
|
|
54
54
|
)
|
|
55
55
|
);
|
|
@@ -124,10 +124,10 @@ const w = (i, t, e) => new Proxy((...s) => {
|
|
|
124
124
|
return w(i, [], e.clone(r));
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
return e.run(t,
|
|
128
|
-
if (
|
|
129
|
-
throw
|
|
130
|
-
return
|
|
127
|
+
return e.run(t, n).then((a) => {
|
|
128
|
+
if (a instanceof Error)
|
|
129
|
+
throw a;
|
|
130
|
+
return a;
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
133
|
}), j = (i, t = "", e) => new Proxy(() => {
|
|
@@ -136,7 +136,7 @@ const w = (i, t, e) => new Proxy((...s) => {
|
|
|
136
136
|
return j(i, `${t}/${o.toString()}`, e);
|
|
137
137
|
},
|
|
138
138
|
apply(s, o, [
|
|
139
|
-
{ $query: n, $fetch: r, $body:
|
|
139
|
+
{ $query: n, $fetch: r, $body: a, ...d } = {
|
|
140
140
|
$fetch: void 0,
|
|
141
141
|
$query: void 0,
|
|
142
142
|
$body: void 0
|
|
@@ -151,7 +151,7 @@ const w = (i, t, e) => new Proxy((...s) => {
|
|
|
151
151
|
l.startsWith("https://") ? "wss://" : "ws://"
|
|
152
152
|
)
|
|
153
153
|
);
|
|
154
|
-
const u =
|
|
154
|
+
const u = a ?? (Object.keys(d).length ? d : void 0), v = typeof u == "object";
|
|
155
155
|
return fetch(l, {
|
|
156
156
|
method: h,
|
|
157
157
|
body: v ? JSON.stringify(u) : u,
|
|
@@ -162,26 +162,26 @@ const w = (i, t, e) => new Proxy((...s) => {
|
|
|
162
162
|
...(b = e.fetch) == null ? void 0 : b.headers,
|
|
163
163
|
...r == null ? void 0 : r.headers
|
|
164
164
|
} : void 0
|
|
165
|
-
}).then(async (
|
|
165
|
+
}).then(async (c) => {
|
|
166
166
|
var x, $;
|
|
167
|
-
if (
|
|
167
|
+
if (c.status > 300) {
|
|
168
168
|
let g;
|
|
169
|
-
if ((x =
|
|
169
|
+
if ((x = c.headers.get("content-type")) != null && x.includes("application/json"))
|
|
170
170
|
try {
|
|
171
|
-
g = await
|
|
171
|
+
g = await c.json();
|
|
172
172
|
} catch {
|
|
173
|
-
g = await
|
|
173
|
+
g = await c.text();
|
|
174
174
|
}
|
|
175
175
|
else
|
|
176
|
-
g = await
|
|
177
|
-
return new E(
|
|
176
|
+
g = await c.text();
|
|
177
|
+
return new E(c.status, g);
|
|
178
178
|
}
|
|
179
|
-
if (($ =
|
|
179
|
+
if (($ = c.headers.get("content-type")) != null && $.includes("application/json"))
|
|
180
180
|
try {
|
|
181
|
-
return await
|
|
181
|
+
return await c.json();
|
|
182
182
|
} catch {
|
|
183
183
|
}
|
|
184
|
-
let f = await
|
|
184
|
+
let f = await c.text();
|
|
185
185
|
return Number.isNaN(+f) ? f === "true" ? !0 : f === "false" ? !1 : f : +f;
|
|
186
186
|
});
|
|
187
187
|
}
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(h,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(h=typeof globalThis<"u"?globalThis:h||self,d(h["@elysia/eden"]={}))})(this,function(h){"use strict";class d extends Error{constructor(t,e){super(),this.status=t,this.value=e}}const N=i=>i.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`),P=(i,t,e)=>{if(i.endsWith("/")||(i+="/"),t=N(t.replace(/index/g,"")),!e||!Object.keys(e).length)return`${i}${t}`;let s="";for(const[o,n]of Object.entries(e))s+=`${o}=${n}&`;return`${i}${t}?${s.slice(0,-1)}`};class v{constructor(t,e){this.pendings=[],this.operation=null,this.isFetching=!1,this.url=t,this.config=e,this.sJson=import("superjson").then(s=>({serialize:s.serialize,deserialize:s.deserialize}))}setConfig(t){this.config=t}clone(t){return new v(this.url,t??this.config)}async run(t,e){var n;const s=+this.pendings.length;if(this.pendings.push(e!==void 0?{n:t,p:e}:{n:t}),this.isFetching)return(n=this.operation)==null?void 0:n.then(r=>r[s]);this.isFetching=!0,this.operation=new Promise(r=>{setTimeout(async()=>{var u;const a=[...this.pendings];this.pendings=[];const{serialize:p,deserialize:w}=await this.sJson,l=await fetch(`${this.url}${this.config.fn??"/~fn"}`,{method:"POST",...this.config.fetch,headers:{"content-type":"elysia/fn",...(u=this.config.fetch)==null?void 0:u.headers},body:JSON.stringify(p(a))});l.status===200?r(l.json().then(f=>w(f))):r(Array(a.length).fill(new Error(await l.text())))},33)});const o=await this.operation.then(r=>r[s]);return this.operation=null,this.isFetching=!1,o}}class j{constructor(t){this.ws=new WebSocket(t),this.url=t}send(t){return Array.isArray(t)?(t.forEach(e=>this.send(e)),this):(this.ws.send(typeof t=="object"?JSON.stringify(t):t.toString()),this)}on(t,e,s){return this.addEventListener(t,e,s)}off(t,e,s){return this.ws.removeEventListener(t,e,s),this}addEventListener(t,e,s){return this.ws.addEventListener(t,o=>{if(t==="message"){let n=o.data.toString();const r=n.charCodeAt(0);if(r===47||r===123)try{n=JSON.parse(n)}catch{}else Number.isNaN(+n)?n==="true"?n=!0:n==="fase"&&(n=!1):n=+n;e({...o,data:n})}else e(o)},s),this}removeEventListener(t,e,s){return this.off(t,e,s),this}close(){return this.ws.close(),this}}const b=(i,t,e)=>new Proxy((...s)=>{},{get(s,o,n){return b(i,[...t,o],e)},apply(s,o,n){const r=n[0];if(t.length===1){if(t[0]in Object.prototype||t[0]in Promise.prototype)return s(n);switch(t[0]){case"toJSON":return s(n);case"$set":return e.setConfig(r);case"$clone":return b(i,[],e.clone(r))}}return e.run(t,
|
|
1
|
+
(function(h,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(h=typeof globalThis<"u"?globalThis:h||self,d(h["@elysia/eden"]={}))})(this,function(h){"use strict";class d extends Error{constructor(t,e){super(),this.status=t,this.value=e}}const N=i=>i.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`),P=(i,t,e)=>{if(i.endsWith("/")||(i+="/"),t=N(t.replace(/index/g,"")),!e||!Object.keys(e).length)return`${i}${t}`;let s="";for(const[o,n]of Object.entries(e))s+=`${o}=${n}&`;return`${i}${t}?${s.slice(0,-1)}`};class v{constructor(t,e){this.pendings=[],this.operation=null,this.isFetching=!1,this.url=t,this.config=e,this.sJson=import("superjson").then(s=>({serialize:s.serialize,deserialize:s.deserialize}))}setConfig(t){this.config=t}clone(t){return new v(this.url,t??this.config)}async run(t,e){var n;const s=+this.pendings.length;if(this.pendings.push(e!==void 0?{n:t,p:e}:{n:t}),this.isFetching)return(n=this.operation)==null?void 0:n.then(r=>r[s]);this.isFetching=!0,this.operation=new Promise(r=>{setTimeout(async()=>{var u;const a=[...this.pendings];this.pendings=[];const{serialize:p,deserialize:w}=await this.sJson,l=await fetch(`${this.url}${this.config.fn??"/~fn"}`,{method:"POST",...this.config.fetch,headers:{"content-type":"elysia/fn",...(u=this.config.fetch)==null?void 0:u.headers},body:JSON.stringify(p(a))});l.status===200?r(l.json().then(f=>w(f))):r(Array(a.length).fill(new Error(await l.text())))},33)});const o=await this.operation.then(r=>r[s]);return this.operation=null,this.isFetching=!1,o}}class j{constructor(t){this.ws=new WebSocket(t),this.url=t}send(t){return Array.isArray(t)?(t.forEach(e=>this.send(e)),this):(this.ws.send(typeof t=="object"?JSON.stringify(t):t.toString()),this)}on(t,e,s){return this.addEventListener(t,e,s)}off(t,e,s){return this.ws.removeEventListener(t,e,s),this}addEventListener(t,e,s){return this.ws.addEventListener(t,o=>{if(t==="message"){let n=o.data.toString();const r=n.charCodeAt(0);if(r===47||r===123)try{n=JSON.parse(n)}catch{}else Number.isNaN(+n)?n==="true"?n=!0:n==="fase"&&(n=!1):n=+n;e({...o,data:n})}else e(o)},s),this}removeEventListener(t,e,s){return this.off(t,e,s),this}close(){return this.ws.close(),this}}const b=(i,t,e)=>new Proxy((...s)=>{},{get(s,o,n){return b(i,[...t,o],e)},apply(s,o,n){const r=n[0];if(t.length===1){if(t[0]in Object.prototype||t[0]in Promise.prototype)return s(n);switch(t[0]){case"toJSON":return s(n);case"$set":return e.setConfig(r);case"$clone":return b(i,[],e.clone(r))}}return e.run(t,n).then(a=>{if(a instanceof Error)throw a;return a})}}),S=(i,t="",e)=>new Proxy(()=>{},{get(s,o,n){return S(i,`${t}/${o.toString()}`,e)},apply(s,o,[{$query:n,$fetch:r,$body:a,...p}={$fetch:void 0,$query:void 0,$body:void 0}]=[{}]){var E;const w=t.lastIndexOf("/"),l=t.slice(w+1),u=P(i,t.slice(0,w),n);if(l==="subscribe")return new j(u.replace(/^([^]+):\/\//,u.startsWith("https://")?"wss://":"ws://"));const f=a??(Object.keys(p).length?p:void 0),x=typeof f=="object";return fetch(u,{method:l,body:x?JSON.stringify(f):f,...e.fetch,...r,headers:f?{"content-type":x?"application/json":"text/plain",...(E=e.fetch)==null?void 0:E.headers,...r==null?void 0:r.headers}:void 0}).then(async c=>{var $,O;if(c.status>300){let y;if(($=c.headers.get("content-type"))!=null&&$.includes("application/json"))try{y=await c.json()}catch{y=await c.text()}else y=await c.text();return new d(c.status,y)}if((O=c.headers.get("content-type"))!=null&&O.includes("application/json"))try{return await c.json()}catch{}let g=await c.text();return Number.isNaN(+g)?g==="true"?!0:g==="false"?!1:g:+g})}}),m=(i,t={})=>new Proxy({},{get(e,s){return s==="$fn"?b(i,[],new v(i,t)):S(i,s,t)}});h.EdenWS=j,h.eden=m,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elysiajs/eden",
|
|
3
|
-
"version": "0.3.0-exp-230222.
|
|
3
|
+
"version": "0.3.0-exp-230222.2210",
|
|
4
4
|
"description": "Fully type-safe Elysia client",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "saltyAom",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"release": "npm run build && npm run test && npm publish --access public"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"elysia": ">= 0.3.0-
|
|
39
|
+
"elysia": ">= 0.3.0-exp-230222.2123"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@elysiajs/cors": "^0.1.0",
|