@elysiajs/eden 0.4.1 → 0.5.0
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/fetch/types.d.ts +1 -0
- package/dist/fetch.js +1 -1
- package/dist/fetch.mjs +1 -1
- package/dist/fn/types.d.ts +1 -0
- package/dist/fn.js +1 -1
- package/dist/fn.mjs +61 -48
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/treaty/index.d.ts +1 -0
- package/dist/treaty.js +1 -1
- package/dist/treaty.mjs +29 -24
- package/dist/utils-5a40996f.mjs +14 -0
- package/dist/utils-a2cfc56a.js +1 -0
- package/package.json +11 -11
- package/src/fn/index.ts +3 -0
- package/src/treaty/index.ts +2 -1
- package/dist/treaty/types.d.ts +0 -79
- package/dist/utils-0d2b8b1a.mjs +0 -8
- package/dist/utils-0d7d9b21.js +0 -1
package/dist/fetch/types.d.ts
CHANGED
package/dist/fetch.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./utils-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./utils-a2cfc56a.js"),o=(f,p)=>async(c,{params:i,body:a,...n}={})=>{var u;i&&Object.entries(i).forEach(([e,t])=>{c=c.replace(`:${e}`,t)});const s=(u=n.headers)==null?void 0:u["Content-Type"];if(!s||s==="application/json")try{a=JSON.stringify(a)}catch{}return fetch(f+c,{...n,headers:a?{"content-type":"application/json",...n.headers}:n.headers,body:a}).then(async e=>{var l;let t;switch((l=e.headers.get("Content-Type"))==null?void 0:l.split(";")[0]){case"application/json":t=await e.json();break;default:t=await e.text().then(r=>Number.isNaN(+r)?r==="true"?!0:r==="false"?!1:r:+r);break}return e.status>300?{data:null,error:new h.EdenFetchError(e.status,t)}:{data:t,error:null}})};exports.edenFetch=o;
|
package/dist/fetch.mjs
CHANGED
package/dist/fn/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bun-types" />
|
|
1
2
|
import type { Elysia, EXPOSED } from 'elysia';
|
|
2
3
|
export declare namespace EdenFn {
|
|
3
4
|
type Create<App extends Elysia<any>> = App['meta'] extends Record<typeof EXPOSED, infer Schema extends Record<string, any>> ? EdenFn.Compose<Schema> : 'Please install Elysia before using Eden';
|
package/dist/fn.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var w=Object.create;var f=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var S=(e,t,n)=>t in e?f(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var b=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of F(t))!O.call(e,s)&&s!==n&&f(e,s,{get:()=>t[s],enumerable:!(i=z(t,s))||i.enumerable});return e};var J=(e,t,n)=>(n=e!=null?w(P(e)):{},b(t||!e||!e.__esModule?f(n,"default",{value:e,enumerable:!0}):n,e));var h=(e,t,n)=>(S(e,typeof t!="symbol"?t+"":t,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class g{constructor(t,n={}){h(this,"url");h(this,"config");h(this,"pendings",[]);h(this,"operation",null);h(this,"isFetching",!1);h(this,"sJson");this.url=t,this.config=n,this.sJson=import("superjson").then(i=>({serialize:i.serialize,deserialize:i.deserialize}))}setConfig(t){this.config=t}clone(t){return new g(this.url,t??this.config)}async run(t,n){var o;const i=+this.pendings.length;if(this.pendings.push(n!==void 0?{n:t,p:n}:{n:t}),this.isFetching)return(o=this.operation)==null?void 0:o.then(r=>r[i]);this.isFetching=!0,this.operation=new Promise(r=>{setTimeout(async()=>{var p;const c=[...this.pendings];this.pendings=[];const{serialize:l,deserialize:y}=await this.sJson,a=await fetch(`${this.url}${this.config.fn??"/~fn"}`,{method:"POST",...this.config.fetch,headers:{"content-type":"elysia/fn",...(p=this.config.fetch)==null?void 0:p.headers},body:JSON.stringify(l(c))});a.status===200?r(a.json().then(d=>y(d))):r(Array(c.length).fill(new Error(await a.text())))},33)});const s=await this.operation.then(r=>r[i]);return this.operation=null,this.isFetching=!1,s}}const u=(e,t,n)=>new Proxy((...i)=>{},{get(i,s,o){return u(e,[...t,s],n)},apply(i,s,o){const r=o[0],c=t[0];if(t.length===1){if(c in Object.prototype||c in Promise.prototype)return i(...o);switch(c){case"toJSON":return i(...o);case"$set":return n.setConfig(r);case"$clone":return u(e,[],n.clone(r))}}return n.run(t,o).then(l=>{if(l instanceof Error)throw l;return l})}}),$=(e,t)=>u(e,[],new g(e,t));exports.edenFn=$;
|
package/dist/fn.mjs
CHANGED
|
@@ -1,80 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var w = Object.defineProperty;
|
|
2
|
+
var d = (n, t, e) => t in n ? w(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
3
|
+
var o = (n, t, e) => (d(n, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
|
+
class u {
|
|
5
|
+
constructor(t, e = {}) {
|
|
6
|
+
o(this, "url");
|
|
7
|
+
o(this, "config");
|
|
8
|
+
o(this, "pendings", []);
|
|
9
|
+
o(this, "operation", null);
|
|
10
|
+
o(this, "isFetching", !1);
|
|
11
|
+
o(this, "sJson");
|
|
12
|
+
this.url = t, this.config = e, this.sJson = import("superjson").then((i) => ({
|
|
13
|
+
serialize: i.serialize,
|
|
14
|
+
deserialize: i.deserialize
|
|
6
15
|
}));
|
|
7
16
|
}
|
|
8
17
|
setConfig(t) {
|
|
9
18
|
this.config = t;
|
|
10
19
|
}
|
|
11
20
|
clone(t) {
|
|
12
|
-
return new
|
|
21
|
+
return new u(this.url, t ?? this.config);
|
|
13
22
|
}
|
|
14
|
-
async run(t,
|
|
15
|
-
var
|
|
16
|
-
const
|
|
23
|
+
async run(t, e) {
|
|
24
|
+
var r;
|
|
25
|
+
const i = +this.pendings.length;
|
|
17
26
|
if (this.pendings.push(
|
|
18
|
-
|
|
27
|
+
e !== void 0 ? { n: t, p: e } : { n: t }
|
|
19
28
|
), this.isFetching)
|
|
20
|
-
return (
|
|
21
|
-
this.isFetching = !0, this.operation = new Promise((
|
|
29
|
+
return (r = this.operation) == null ? void 0 : r.then((s) => s[i]);
|
|
30
|
+
this.isFetching = !0, this.operation = new Promise((s) => {
|
|
22
31
|
setTimeout(async () => {
|
|
23
|
-
var
|
|
24
|
-
const
|
|
32
|
+
var g;
|
|
33
|
+
const h = [...this.pendings];
|
|
25
34
|
this.pendings = [];
|
|
26
|
-
const { serialize:
|
|
35
|
+
const { serialize: c, deserialize: p } = await this.sJson, f = await fetch(
|
|
27
36
|
`${this.url}${this.config.fn ?? "/~fn"}`,
|
|
28
37
|
{
|
|
29
38
|
method: "POST",
|
|
30
39
|
...this.config.fetch,
|
|
31
40
|
headers: {
|
|
32
41
|
"content-type": "elysia/fn",
|
|
33
|
-
...(
|
|
42
|
+
...(g = this.config.fetch) == null ? void 0 : g.headers
|
|
34
43
|
},
|
|
35
|
-
body: JSON.stringify(h
|
|
44
|
+
body: JSON.stringify(c(h))
|
|
36
45
|
}
|
|
37
46
|
);
|
|
38
|
-
|
|
39
|
-
Array(
|
|
40
|
-
new Error(await
|
|
47
|
+
f.status === 200 ? s(f.json().then((y) => p(y))) : s(
|
|
48
|
+
Array(h.length).fill(
|
|
49
|
+
new Error(await f.text())
|
|
41
50
|
)
|
|
42
51
|
);
|
|
43
52
|
}, 33);
|
|
44
53
|
});
|
|
45
|
-
const
|
|
46
|
-
return this.operation = null, this.isFetching = !1,
|
|
54
|
+
const a = await this.operation.then((s) => s[i]);
|
|
55
|
+
return this.operation = null, this.isFetching = !1, a;
|
|
47
56
|
}
|
|
48
57
|
}
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
const l = (n, t, e) => (
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
60
|
+
new Proxy((...i) => {
|
|
61
|
+
}, {
|
|
62
|
+
get(i, a, r) {
|
|
63
|
+
return l(n, [...t, a], e);
|
|
64
|
+
},
|
|
65
|
+
apply(i, a, r) {
|
|
66
|
+
const s = r[0], h = t[0];
|
|
67
|
+
if (t.length === 1) {
|
|
68
|
+
if (h in Object.prototype || h in Promise.prototype)
|
|
69
|
+
return i(...r);
|
|
70
|
+
switch (h) {
|
|
71
|
+
case "toJSON":
|
|
72
|
+
return i(...r);
|
|
73
|
+
case "$set":
|
|
74
|
+
return e.setConfig(s);
|
|
75
|
+
case "$clone":
|
|
76
|
+
return l(n, [], e.clone(s));
|
|
77
|
+
}
|
|
66
78
|
}
|
|
79
|
+
return e.run(t, r).then((c) => {
|
|
80
|
+
if (c instanceof Error)
|
|
81
|
+
throw c;
|
|
82
|
+
return c;
|
|
83
|
+
});
|
|
67
84
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return h;
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}), y = (o, t) => (
|
|
85
|
+
})
|
|
86
|
+
), F = (n, t) => (
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
75
88
|
// @ts-ignore
|
|
76
|
-
|
|
89
|
+
l(n, [], new u(n, t))
|
|
77
90
|
);
|
|
78
91
|
export {
|
|
79
|
-
|
|
92
|
+
F as edenFn
|
|
80
93
|
};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./treaty.js"),t=require("./fetch.js"),r=require("./fn.js");require("./utils-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./treaty.js"),t=require("./fetch.js"),r=require("./fn.js");require("./utils-a2cfc56a.js");exports.edenTreaty=e.edenTreaty;exports.edenFetch=t.edenFetch;exports.edenFn=r.edenFn;
|
package/dist/index.mjs
CHANGED
package/dist/treaty/index.d.ts
CHANGED
package/dist/treaty.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";var N=Object.defineProperty;var O=(r,e,t)=>e in r?N(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var w=(r,e,t)=>(O(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./utils-a2cfc56a.js"),j=(r,e,t)=>{if(r.endsWith("/")||(r+="/"),e==="index"&&(e=""),!t||!Object.keys(t).length)return`${r}${e}`;let n="";for(const[f,s]of Object.entries(t))n+=`${f}=${s}&`;return`${r}${e}?${n.slice(0,-1)}`},v=r=>typeof FileList>"u"?!1:r instanceof FileList||r instanceof File,k=r=>{for(let e in r){if(v(r[e]))return!0;if(Array.isArray(r[e])&&r[e].find(t=>v(t)))return!0}return!1},E=r=>new Promise(e=>{const t=new FileReader;t.onload=()=>{e(new Blob([t.result],{type:r.type}))},t.readAsArrayBuffer(r)});class F{constructor(e){w(this,"ws");w(this,"url");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,n){return this.addEventListener(e,t,n)}off(e,t,n){return this.ws.removeEventListener(e,t,n),this}subscribe(e,t){return this.addEventListener("message",e,t)}addEventListener(e,t,n){return this.ws.addEventListener(e,f=>{if(e==="message"){let s=f.data.toString();const i=s.charCodeAt(0);if(i===47||i===123)try{s=JSON.parse(s)}catch{}else Number.isNaN(+s)?s==="true"?s=!0:s==="fase"&&(s=!1):s=+s;t({...f,data:s})}else t(f)},n),this}removeEventListener(e,t,n){return this.off(e,t,n),this}close(){return this.ws.close(),this}}const S=(r,e="",t)=>new Proxy(()=>{},{get(n,f,s){return S(r,`${e}/${f.toString()}`)},apply(n,f,[{$query:s,$fetch:i,$body:L,...g}={$fetch:void 0,$query:void 0,$body:void 0}]=[{}]){const p=e.lastIndexOf("/"),h=e.slice(p+1),d=j(r,e.slice(0,p),s);return h==="subscribe"?new F(d.replace(/^([^]+):\/\//,d.startsWith("https://")?"wss://":"ws://")):(async()=>{let c=L??(Object.keys(g).length?g:void 0);const y=typeof c=="object",b=y&&k(c);if(b){const o=new FormData;for(const[a,l]of Object.entries(c))if(l instanceof File)o.append(a,await E(l));else if(l instanceof FileList)for(let u=0;u<l.length;u++)o.append(a,await E(l[u]));else o.append(a,l);c=o}else y&&(c=JSON.stringify(c));return fetch(d,{method:h,body:c,...i,headers:c?b?i==null?void 0:i.headers:{"content-type":y?"application/json":"text/plain",...i==null?void 0:i.headers}:i==null?void 0:i.headers}).then(async o=>{var l;let a;switch((l=o.headers.get("Content-Type"))==null?void 0:l.split(";")[0]){case"application/json":a=await o.json();break;default:a=await o.text().then(u=>Number.isNaN(+u)?u==="true"?!0:u==="false"?!1:u:+u)}return o.status>300?{data:a,error:new m.EdenFetchError(o.status,await a)}:{data:a,error:null}})})()}}),x=(r,e={})=>new Proxy({},{get(t,n){return S(r,n)}});exports.EdenWS=F;exports.edenTreaty=x;
|
package/dist/treaty.mjs
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var L = Object.defineProperty;
|
|
2
|
+
var N = (r, e, t) => e in r ? L(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var w = (r, e, t) => (N(r, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { E as x } from "./utils-5a40996f.mjs";
|
|
5
|
+
const O = (r, e, t) => {
|
|
3
6
|
if (r.endsWith("/") || (r += "/"), e === "index" && (e = ""), !t || !Object.keys(t).length)
|
|
4
7
|
return `${r}${e}`;
|
|
5
8
|
let n = "";
|
|
6
9
|
for (const [f, s] of Object.entries(t))
|
|
7
10
|
n += `${f}=${s}&`;
|
|
8
11
|
return `${r}${e}?${n.slice(0, -1)}`;
|
|
9
|
-
},
|
|
12
|
+
}, v = (r) => typeof FileList > "u" ? !1 : r instanceof FileList || r instanceof File, S = (r) => {
|
|
10
13
|
for (let e in r) {
|
|
11
|
-
if (
|
|
14
|
+
if (v(r[e]))
|
|
12
15
|
return !0;
|
|
13
|
-
if (Array.isArray(r[e]) && r[e].find((t) =>
|
|
16
|
+
if (Array.isArray(r[e]) && r[e].find((t) => v(t)))
|
|
14
17
|
return !0;
|
|
15
18
|
}
|
|
16
19
|
return !1;
|
|
17
|
-
},
|
|
20
|
+
}, E = (r) => new Promise((e) => {
|
|
18
21
|
const t = new FileReader();
|
|
19
22
|
t.onload = () => {
|
|
20
23
|
e(new Blob([t.result], { type: r.type }));
|
|
21
24
|
}, t.readAsArrayBuffer(r);
|
|
22
25
|
});
|
|
23
|
-
class
|
|
26
|
+
class k {
|
|
24
27
|
constructor(e) {
|
|
28
|
+
w(this, "ws");
|
|
29
|
+
w(this, "url");
|
|
25
30
|
this.ws = new WebSocket(e), this.url = e;
|
|
26
31
|
}
|
|
27
32
|
send(e) {
|
|
@@ -69,37 +74,37 @@ class x {
|
|
|
69
74
|
return this.ws.close(), this;
|
|
70
75
|
}
|
|
71
76
|
}
|
|
72
|
-
const
|
|
77
|
+
const F = (r, e = "", t) => new Proxy(() => {
|
|
73
78
|
}, {
|
|
74
79
|
get(n, f, s) {
|
|
75
|
-
return
|
|
80
|
+
return F(r, `${e}/${f.toString()}`);
|
|
76
81
|
},
|
|
77
82
|
apply(n, f, [
|
|
78
|
-
{ $query: s, $fetch: i, $body:
|
|
83
|
+
{ $query: s, $fetch: i, $body: m, ...p } = {
|
|
79
84
|
$fetch: void 0,
|
|
80
85
|
$query: void 0,
|
|
81
86
|
$body: void 0
|
|
82
87
|
}
|
|
83
88
|
] = [{}]) {
|
|
84
|
-
const
|
|
85
|
-
return
|
|
89
|
+
const g = e.lastIndexOf("/"), h = e.slice(g + 1), d = O(r, e.slice(0, g), s);
|
|
90
|
+
return h === "subscribe" ? new k(
|
|
86
91
|
d.replace(
|
|
87
92
|
/^([^]+):\/\//,
|
|
88
93
|
d.startsWith("https://") ? "wss://" : "ws://"
|
|
89
94
|
)
|
|
90
95
|
) : (async () => {
|
|
91
|
-
let c =
|
|
92
|
-
const y = typeof c == "object",
|
|
93
|
-
if (
|
|
96
|
+
let c = m ?? (Object.keys(p).length ? p : void 0);
|
|
97
|
+
const y = typeof c == "object", b = y && S(c);
|
|
98
|
+
if (b) {
|
|
94
99
|
const o = new FormData();
|
|
95
100
|
for (const [a, l] of Object.entries(c))
|
|
96
101
|
if (l instanceof File)
|
|
97
|
-
o.append(a, await
|
|
102
|
+
o.append(a, await E(l));
|
|
98
103
|
else if (l instanceof FileList)
|
|
99
104
|
for (let u = 0; u < l.length; u++)
|
|
100
105
|
o.append(
|
|
101
106
|
a,
|
|
102
|
-
await
|
|
107
|
+
await E(l[u])
|
|
103
108
|
);
|
|
104
109
|
else
|
|
105
110
|
o.append(a, l);
|
|
@@ -107,11 +112,11 @@ const E = (r, e = "", t) => new Proxy(() => {
|
|
|
107
112
|
} else
|
|
108
113
|
y && (c = JSON.stringify(c));
|
|
109
114
|
return fetch(d, {
|
|
110
|
-
method:
|
|
115
|
+
method: h,
|
|
111
116
|
body: c,
|
|
112
117
|
// ...config.fetch,
|
|
113
118
|
...i,
|
|
114
|
-
headers: c ?
|
|
119
|
+
headers: c ? b ? i == null ? void 0 : i.headers : {
|
|
115
120
|
"content-type": y ? "application/json" : "text/plain",
|
|
116
121
|
...i == null ? void 0 : i.headers
|
|
117
122
|
} : i == null ? void 0 : i.headers
|
|
@@ -127,20 +132,20 @@ const E = (r, e = "", t) => new Proxy(() => {
|
|
|
127
132
|
}
|
|
128
133
|
return o.status > 300 ? {
|
|
129
134
|
data: a,
|
|
130
|
-
error: new
|
|
135
|
+
error: new x(o.status, await a)
|
|
131
136
|
} : { data: a, error: null };
|
|
132
137
|
});
|
|
133
138
|
})();
|
|
134
139
|
}
|
|
135
|
-
}),
|
|
140
|
+
}), P = (r, e = {}) => new Proxy(
|
|
136
141
|
{},
|
|
137
142
|
{
|
|
138
143
|
get(t, n) {
|
|
139
|
-
return
|
|
144
|
+
return F(r, n);
|
|
140
145
|
}
|
|
141
146
|
}
|
|
142
147
|
);
|
|
143
148
|
export {
|
|
144
|
-
|
|
145
|
-
|
|
149
|
+
k as EdenWS,
|
|
150
|
+
P as edenTreaty
|
|
146
151
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var u = Object.defineProperty;
|
|
2
|
+
var o = (r, s, t) => s in r ? u(r, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[s] = t;
|
|
3
|
+
var e = (r, s, t) => (o(r, typeof s != "symbol" ? s + "" : s, t), t);
|
|
4
|
+
class E extends Error {
|
|
5
|
+
constructor(t, a) {
|
|
6
|
+
super();
|
|
7
|
+
e(this, "status");
|
|
8
|
+
e(this, "value");
|
|
9
|
+
this.status = t, this.value = a;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
E
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var a=(t,r,s)=>r in t?c(t,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[r]=s;var e=(t,r,s)=>(a(t,typeof r!="symbol"?r+"":r,s),s);class o extends Error{constructor(s,u){super();e(this,"status");e(this,"value");this.status=s,this.value=u}}exports.EdenFetchError=o;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elysiajs/eden",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Fully type-safe Elysia client",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "saltyAom",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"release": "npm run build && npm run test && npm publish --access public"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@
|
|
58
|
-
"@
|
|
59
|
-
"elysia": ">= 0.
|
|
57
|
+
"@elysiajs/fn": ">= 0.5.0",
|
|
58
|
+
"@sinclair/typebox": ">= 0.28.10",
|
|
59
|
+
"elysia": ">= 0.5.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependenciesMeta": {
|
|
62
62
|
"@sinclair/typebox": {
|
|
@@ -64,17 +64,17 @@
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@elysiajs/cors": "
|
|
68
|
-
"@elysiajs/fn": "
|
|
67
|
+
"@elysiajs/cors": "0.5.0",
|
|
68
|
+
"@elysiajs/fn": "0.5.0",
|
|
69
69
|
"@sinclair/typebox": "^0.26.8",
|
|
70
70
|
"@types/node": "^18.15.5",
|
|
71
71
|
"bun-types": "^0.5.8",
|
|
72
|
-
"elysia": "
|
|
72
|
+
"elysia": "0.5.0",
|
|
73
73
|
"eslint": "^8.26.0",
|
|
74
|
-
"rimraf": "^
|
|
75
|
-
"typescript": "^5.0.
|
|
76
|
-
"vite": "^4.
|
|
77
|
-
"vite-plugin-dts": "^
|
|
74
|
+
"rimraf": "^4.4.1",
|
|
75
|
+
"typescript": "^5.0.4",
|
|
76
|
+
"vite": "^4.3.5",
|
|
77
|
+
"vite-plugin-dts": "^2.3.0"
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
80
|
"superjson": "^1.12.2"
|
package/src/fn/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
1
2
|
import type { Elysia } from 'elysia'
|
|
2
3
|
|
|
3
4
|
import { Signal } from './utils'
|
|
@@ -10,6 +11,7 @@ const createProxy = (
|
|
|
10
11
|
procedures: string[],
|
|
11
12
|
signal: Signal
|
|
12
13
|
): Record<string, unknown> =>
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
13
15
|
new Proxy((..._: any[]) => {}, {
|
|
14
16
|
get(target, key, value) {
|
|
15
17
|
return createProxy(domain, [...procedures, key as string], signal)
|
|
@@ -49,5 +51,6 @@ export const edenFn = <App extends Elysia<any>>(
|
|
|
49
51
|
domain: string,
|
|
50
52
|
config?: EdenFn.Config
|
|
51
53
|
): EdenFn.Create<App> =>
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
52
55
|
// @ts-ignore
|
|
53
56
|
createProxy(domain, [], new Signal(domain, config))
|
package/src/treaty/index.ts
CHANGED
|
@@ -7,10 +7,11 @@ import type { EdenTreaty } from './types'
|
|
|
7
7
|
|
|
8
8
|
export type { EdenTreaty } from './types'
|
|
9
9
|
|
|
10
|
-
// @ts-ignore
|
|
11
10
|
const isFile = (v: any) => {
|
|
11
|
+
// @ts-ignore
|
|
12
12
|
if (typeof FileList === 'undefined') return false
|
|
13
13
|
|
|
14
|
+
// @ts-ignore
|
|
14
15
|
return v instanceof FileList || v instanceof File
|
|
15
16
|
}
|
|
16
17
|
|
package/dist/treaty/types.d.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { Elysia, SCHEMA, AnyTypedSchema } from 'elysia';
|
|
2
|
-
import type { EdenWS } from './index';
|
|
3
|
-
import type { IsNever, IsUnknown, MapError, UnionToIntersect } from '../types';
|
|
4
|
-
import { EdenFetchError } from '../utils';
|
|
5
|
-
type Replace<RecordType, TargetType, GenericType> = {
|
|
6
|
-
[K in keyof RecordType]: RecordType[K] extends TargetType ? GenericType : RecordType[K];
|
|
7
|
-
};
|
|
8
|
-
export declare namespace EdenTreaty {
|
|
9
|
-
type Create<App extends Elysia<any>> = App['meta'] extends Record<typeof SCHEMA, infer Schema extends Record<string, any>> ? EdenTreaty.Sign<Schema> : 'Please install Elysia before using Eden';
|
|
10
|
-
interface Config {
|
|
11
|
-
}
|
|
12
|
-
type Sign<A> = {
|
|
13
|
-
[Path in keyof A as Path extends `/${infer Prefix}/${infer _}` ? Prefix : Path extends `/` ? 'index' : Path extends `/${infer Prefix}` ? Prefix : never]: UnionToIntersect<Path extends `/${infer _}/${infer Rest}` ? NestPath<Rest, {
|
|
14
|
-
[Method in keyof A[Path]]: A[Path][Method] extends infer Route extends AnyTypedSchema ? Method extends 'subscribe' ? undefined extends Route['query'] ? (params?: {
|
|
15
|
-
$query?: Record<string, string>;
|
|
16
|
-
}) => EdenWS<Route> : (params: {
|
|
17
|
-
$query: Route['query'];
|
|
18
|
-
}) => EdenWS<Route> : IsUnknown<Route['body']> extends true ? (params?: {
|
|
19
|
-
$query?: Record<string, string>;
|
|
20
|
-
$fetch?: RequestInit;
|
|
21
|
-
}) => Promise<{
|
|
22
|
-
data: Route['response']['200'];
|
|
23
|
-
error: null;
|
|
24
|
-
} | {
|
|
25
|
-
data: null;
|
|
26
|
-
error: MapError<Route['response']> extends infer Errors ? IsNever<Errors> extends true ? EdenFetchError<number, string> : Errors : EdenFetchError<number, string>;
|
|
27
|
-
}> : (params: Replace<Route['body'], Blob | Blob[], File | FileList> & {
|
|
28
|
-
$query?: Record<string, string>;
|
|
29
|
-
$fetch?: RequestInit;
|
|
30
|
-
}) => Promise<{
|
|
31
|
-
data: Route['response'] extends {
|
|
32
|
-
200: infer ReturnedType;
|
|
33
|
-
} ? ReturnedType : unknown;
|
|
34
|
-
error: null;
|
|
35
|
-
} | {
|
|
36
|
-
data: null;
|
|
37
|
-
error: MapError<Route['response']> extends infer Errors ? IsNever<Errors> extends true ? EdenFetchError<number, string> : Errors : EdenFetchError<number, string>;
|
|
38
|
-
}> : never;
|
|
39
|
-
}> : {
|
|
40
|
-
[Method in keyof A[Path]]: A[Path][Method] extends infer Route extends AnyTypedSchema ? Method extends 'subscribe' ? undefined extends Route['query'] ? (params?: {
|
|
41
|
-
$query?: Record<string, string>;
|
|
42
|
-
}) => EdenWS<Route> : (params: {
|
|
43
|
-
$query: Route['query'];
|
|
44
|
-
}) => EdenWS<Route> : IsUnknown<Route['body']> extends true ? (params?: {
|
|
45
|
-
$query?: Record<string, string>;
|
|
46
|
-
$fetch?: RequestInit;
|
|
47
|
-
}) => Promise<{
|
|
48
|
-
data: Route['response']['200'];
|
|
49
|
-
error: null;
|
|
50
|
-
} | {
|
|
51
|
-
data: null;
|
|
52
|
-
error: MapError<Route['response']> extends infer Errors ? IsNever<Errors> extends true ? EdenFetchError<number, string> : Errors : EdenFetchError<number, string>;
|
|
53
|
-
}> : (params: Replace<Route['body'], Blob | Blob[], File | FileList> & {
|
|
54
|
-
$query?: Record<string, string>;
|
|
55
|
-
$fetch?: RequestInit;
|
|
56
|
-
}) => Promise<{
|
|
57
|
-
data: Route['response'] extends {
|
|
58
|
-
200: infer ReturnedType;
|
|
59
|
-
} ? ReturnedType : unknown;
|
|
60
|
-
error: null;
|
|
61
|
-
} | {
|
|
62
|
-
data: null;
|
|
63
|
-
error: MapError<Route['response']> extends infer Errors ? IsNever<Errors> extends true ? EdenFetchError<number, string> : Errors : EdenFetchError<number, string>;
|
|
64
|
-
}> : never;
|
|
65
|
-
}>;
|
|
66
|
-
};
|
|
67
|
-
interface OnMessage<Data = unknown> extends MessageEvent {
|
|
68
|
-
data: Data;
|
|
69
|
-
rawData: MessageEvent['data'];
|
|
70
|
-
}
|
|
71
|
-
type WSEvent<K extends keyof WebSocketEventMap, Data = unknown> = K extends 'message' ? OnMessage<Data> : WebSocketEventMap[K];
|
|
72
|
-
interface CallOption {
|
|
73
|
-
[x: string]: any;
|
|
74
|
-
$fetch?: RequestInit;
|
|
75
|
-
$query?: Record<string, string>;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
type NestPath<T extends string, V> = T extends `${infer First}/${infer Rest}` ? First extends `:${infer Parameter}` ? Record<(string & {}) | number | `:${Parameter}`, NestPath<Rest, V>> : Record<First, NestPath<Rest, V>> : T extends `:${infer Parameter}` ? Record<(string & {}) | number | T, V> : Record<T, V>;
|
|
79
|
-
export {};
|
package/dist/utils-0d2b8b1a.mjs
DELETED
package/dist/utils-0d7d9b21.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";class t extends Error{constructor(r,s){super(),this.status=r,this.value=s}}exports.EdenFetchError=t;
|