@elysiajs/eden 0.6.1 → 0.6.3
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/errors.js +10 -0
- package/dist/errors.js.map +1 -0
- package/dist/fetch/index.js +67 -0
- package/dist/fetch/index.js.map +1 -0
- package/dist/fetch/types.js +2 -0
- package/dist/fetch/types.js.map +1 -0
- package/dist/fetch.js +1 -1
- package/dist/fetch.mjs +32 -22
- package/dist/fn/index.js +35 -0
- package/dist/fn/index.js.map +1 -0
- package/dist/fn/types.js +2 -0
- package/dist/fn/types.js.map +1 -0
- package/dist/fn/utils.js +59 -0
- package/dist/fn/utils.js.map +1 -0
- package/dist/index.js +25 -1
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1 -1
- package/dist/treaty/index.js +205 -0
- package/dist/treaty/index.js.map +1 -0
- package/dist/treaty/types.js +2 -0
- package/dist/treaty/types.js.map +1 -0
- package/dist/treaty/utils.js +13 -0
- package/dist/treaty/utils.js.map +1 -0
- package/dist/treaty.js +1 -1
- package/dist/treaty.mjs +108 -112
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +84 -79
- package/src/fetch/index.ts +19 -5
- package/src/fetch/types.ts +32 -13
- package/src/treaty/index.ts +57 -52
- package/src/treaty/types.ts +116 -205
- package/src/types.ts +1 -1
- package/dist/fetch/index.d.ts +0 -5
- package/dist/fetch/index.d.ts.map +0 -1
- package/dist/fetch/types.d.ts +0 -36
- package/dist/fetch/types.d.ts.map +0 -1
- package/dist/fn/index.d.ts +0 -5
- package/dist/fn/index.d.ts.map +0 -1
- package/dist/fn/types.d.ts +0 -28
- package/dist/fn/types.d.ts.map +0 -1
- package/dist/fn/utils.d.ts +0 -14
- package/dist/fn/utils.d.ts.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/treaty/index.d.ts +0 -18
- package/dist/treaty/index.d.ts.map +0 -1
- package/dist/treaty/utils.d.ts +0 -2
- package/dist/treaty/utils.d.ts.map +0 -1
- package/dist/types.d.ts +0 -26
- package/dist/types.d.ts.map +0 -1
- package/dist/utils.d.ts +0 -6
- package/dist/utils.d.ts.map +0 -1
- /package/dist/{utils-5a40996f.mjs → errors-5a40996f.mjs} +0 -0
- /package/dist/{utils-a2cfc56a.js → errors-a2cfc56a.js} +0 -0
- /package/src/{utils.ts → errors.ts} +0 -0
package/dist/treaty.mjs
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
var A = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { E as
|
|
5
|
-
const
|
|
6
|
-
if (
|
|
7
|
-
return `${
|
|
2
|
+
var O = (s, e, t) => e in s ? A(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var b = (s, e, t) => (O(s, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { E as k } from "./errors-5a40996f.mjs";
|
|
5
|
+
const j = (s, e, t) => {
|
|
6
|
+
if (s.endsWith("/") || (s += "/"), e === "index" && (e = ""), !t || !Object.keys(t).length)
|
|
7
|
+
return `${s}${e}`;
|
|
8
8
|
let n = "";
|
|
9
|
-
for (const [
|
|
10
|
-
n += `${
|
|
11
|
-
return `${
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
for (const [o, r] of Object.entries(t))
|
|
10
|
+
n += `${o}=${r}&`;
|
|
11
|
+
return `${s}${e}?${n.slice(0, -1)}`;
|
|
12
|
+
}, g = typeof FileList > "u", L = (s) => g ? s instanceof Blob : s instanceof FileList || s instanceof File, B = (s) => {
|
|
13
|
+
if (!s)
|
|
14
|
+
return !1;
|
|
15
|
+
for (const e in s) {
|
|
16
|
+
if (L(s[e]))
|
|
15
17
|
return !0;
|
|
16
|
-
if (Array.isArray(
|
|
18
|
+
if (Array.isArray(s[e]) && s[e].find((t) => L(t)))
|
|
17
19
|
return !0;
|
|
18
20
|
}
|
|
19
21
|
return !1;
|
|
20
|
-
},
|
|
22
|
+
}, N = (s) => g ? s : new Promise((e) => {
|
|
21
23
|
const t = new FileReader();
|
|
22
24
|
t.onload = () => {
|
|
23
|
-
e(new Blob([t.result], { type:
|
|
24
|
-
}, t.readAsArrayBuffer(
|
|
25
|
+
e(new Blob([t.result], { type: s.type }));
|
|
26
|
+
}, t.readAsArrayBuffer(s);
|
|
25
27
|
});
|
|
26
|
-
class
|
|
28
|
+
class P {
|
|
27
29
|
constructor(e) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
b(this, "ws");
|
|
31
|
+
b(this, "url");
|
|
30
32
|
this.ws = new WebSocket(e), this.url = e;
|
|
31
33
|
}
|
|
32
34
|
send(e) {
|
|
@@ -46,23 +48,23 @@ class J {
|
|
|
46
48
|
addEventListener(e, t, n) {
|
|
47
49
|
return this.ws.addEventListener(
|
|
48
50
|
e,
|
|
49
|
-
(
|
|
51
|
+
(o) => {
|
|
50
52
|
if (e === "message") {
|
|
51
|
-
let
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
53
|
+
let r = o.data.toString();
|
|
54
|
+
const c = r.charCodeAt(0);
|
|
55
|
+
if (c === 47 || c === 123)
|
|
54
56
|
try {
|
|
55
|
-
|
|
57
|
+
r = JSON.parse(r);
|
|
56
58
|
} catch {
|
|
57
59
|
}
|
|
58
60
|
else
|
|
59
|
-
Number.isNaN(+
|
|
61
|
+
Number.isNaN(+r) ? r === "true" ? r = !0 : r === "fase" && (r = !1) : r = +r;
|
|
60
62
|
t({
|
|
61
|
-
...
|
|
62
|
-
data:
|
|
63
|
+
...o,
|
|
64
|
+
data: r
|
|
63
65
|
});
|
|
64
66
|
} else
|
|
65
|
-
t(
|
|
67
|
+
t(o);
|
|
66
68
|
},
|
|
67
69
|
n
|
|
68
70
|
), this;
|
|
@@ -74,104 +76,98 @@ class J {
|
|
|
74
76
|
return this.ws.close(), this;
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
79
|
+
const S = (s, e = "", t) => new Proxy(() => {
|
|
80
|
+
}, {
|
|
81
|
+
get(n, o, r) {
|
|
82
|
+
return S(s, `${e}/${o.toString()}`, t);
|
|
83
|
+
},
|
|
84
|
+
apply(n, o, [
|
|
85
|
+
{ $query: r, $fetch: c, $headers: $, ...E } = {
|
|
86
|
+
$fetch: void 0,
|
|
87
|
+
$headers: void 0,
|
|
88
|
+
$query: void 0
|
|
89
|
+
}
|
|
90
|
+
] = [{}]) {
|
|
91
|
+
const F = e.lastIndexOf("/"), h = e.slice(F + 1), w = j(s, e.slice(0, F), r);
|
|
92
|
+
return h === "subscribe" ? new P(
|
|
93
|
+
w.replace(
|
|
94
|
+
/^([^]+):\/\//,
|
|
95
|
+
w.startsWith("https://") ? "wss://" : "ws://"
|
|
96
|
+
)
|
|
97
|
+
) : (async () => {
|
|
98
|
+
var m, x;
|
|
99
|
+
let f;
|
|
100
|
+
const v = {
|
|
101
|
+
...(m = t.$fetch) == null ? void 0 : m.headers,
|
|
102
|
+
...c == null ? void 0 : c.headers,
|
|
103
|
+
...$
|
|
104
|
+
};
|
|
105
|
+
if (h !== "GET" && h !== "HEAD") {
|
|
106
|
+
f = Object.keys(E).length ? E : void 0;
|
|
107
|
+
const a = typeof f == "object";
|
|
108
|
+
if (a && B(f)) {
|
|
109
|
+
const d = new FormData();
|
|
110
|
+
for (const [y, l] of Object.entries(f))
|
|
111
|
+
if (g)
|
|
112
|
+
d.append(y, l);
|
|
108
113
|
else if (l instanceof File)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
await
|
|
114
|
+
d.append(
|
|
115
|
+
y,
|
|
116
|
+
await N(l)
|
|
112
117
|
);
|
|
113
118
|
else if (l instanceof FileList)
|
|
114
|
-
for (let
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
await
|
|
119
|
+
for (let p = 0; p < l.length; p++)
|
|
120
|
+
d.append(
|
|
121
|
+
y,
|
|
122
|
+
await N(l[p])
|
|
118
123
|
);
|
|
119
124
|
else
|
|
120
|
-
|
|
121
|
-
|
|
125
|
+
d.append(y, l);
|
|
126
|
+
f = d;
|
|
122
127
|
} else
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
} : {
|
|
153
|
-
data: u,
|
|
154
|
-
status: i.status,
|
|
155
|
-
raw: i,
|
|
156
|
-
headers: i.headers,
|
|
157
|
-
error: null,
|
|
158
|
-
retry: y
|
|
159
|
-
};
|
|
128
|
+
v["content-type"] = a ? "application/json" : "text/plain", a && (f = JSON.stringify(f));
|
|
129
|
+
}
|
|
130
|
+
const i = await (t.fetcher ?? fetch)(w, {
|
|
131
|
+
method: h,
|
|
132
|
+
body: f,
|
|
133
|
+
...t.$fetch,
|
|
134
|
+
...c,
|
|
135
|
+
headers: v
|
|
136
|
+
});
|
|
137
|
+
let u;
|
|
138
|
+
switch ((x = i.headers.get("Content-Type")) == null ? void 0 : x.split(";")[0]) {
|
|
139
|
+
case "application/json":
|
|
140
|
+
u = await i.json();
|
|
141
|
+
break;
|
|
142
|
+
default:
|
|
143
|
+
u = await i.text().then((a) => Number.isNaN(+a) ? a === "true" ? !0 : a === "false" ? !1 : a : +a);
|
|
144
|
+
}
|
|
145
|
+
return i.status > 300 ? {
|
|
146
|
+
data: u,
|
|
147
|
+
error: new k(i.status, await u),
|
|
148
|
+
status: i.status,
|
|
149
|
+
raw: i,
|
|
150
|
+
headers: i.headers
|
|
151
|
+
} : {
|
|
152
|
+
data: u,
|
|
153
|
+
status: i.status,
|
|
154
|
+
response: i,
|
|
155
|
+
headers: i.headers,
|
|
156
|
+
error: null
|
|
160
157
|
};
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
), D = (r, e = {
|
|
158
|
+
})();
|
|
159
|
+
}
|
|
160
|
+
}), C = (s, e = {
|
|
165
161
|
fetcher: fetch
|
|
166
162
|
}) => new Proxy(
|
|
167
163
|
{},
|
|
168
164
|
{
|
|
169
165
|
get(t, n) {
|
|
170
|
-
return
|
|
166
|
+
return S(s, n, e);
|
|
171
167
|
}
|
|
172
168
|
}
|
|
173
169
|
);
|
|
174
170
|
export {
|
|
175
|
-
|
|
176
|
-
|
|
171
|
+
P as EdenWS,
|
|
172
|
+
C as edenTreaty
|
|
177
173
|
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,84 +1,89 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
"name": "@elysiajs/eden",
|
|
3
|
+
"version": "0.6.3",
|
|
4
|
+
"description": "Fully type-safe Elysia client",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "saltyAom",
|
|
7
|
+
"url": "https://github.com/SaltyAom",
|
|
8
|
+
"email": "saltyaom@gmail.com"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"require": "./dist/index.js",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"node": "./dist/index.js",
|
|
16
|
+
"default": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts"
|
|
9
18
|
},
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"default": "./dist/index.js",
|
|
17
|
-
"types": "./dist/index.d.ts"
|
|
18
|
-
},
|
|
19
|
-
"./treaty": {
|
|
20
|
-
"require": "./dist/treaty.js",
|
|
21
|
-
"import": "./dist/treaty.mjs",
|
|
22
|
-
"node": "./dist/treaty.js",
|
|
23
|
-
"default": "./dist/treaty.js",
|
|
24
|
-
"types": "./dist/treaty/index.d.ts"
|
|
25
|
-
},
|
|
26
|
-
"./fetch": {
|
|
27
|
-
"require": "./dist/fetch.js",
|
|
28
|
-
"import": "./dist/fetch.mjs",
|
|
29
|
-
"node": "./dist/fetch.js",
|
|
30
|
-
"default": "./dist/fetch.js",
|
|
31
|
-
"types": "./dist/fetch/index.d.ts"
|
|
32
|
-
},
|
|
33
|
-
"./fn": {
|
|
34
|
-
"require": "./dist/fn.js",
|
|
35
|
-
"import": "./dist/fn.mjs",
|
|
36
|
-
"node": "./dist/fn.js",
|
|
37
|
-
"default": "./dist/fn.js",
|
|
38
|
-
"types": "./dist/fn/index.d.ts"
|
|
39
|
-
}
|
|
19
|
+
"./treaty": {
|
|
20
|
+
"require": "./dist/treaty.js",
|
|
21
|
+
"import": "./dist/treaty.mjs",
|
|
22
|
+
"node": "./dist/treaty.js",
|
|
23
|
+
"default": "./dist/treaty.js",
|
|
24
|
+
"types": "./dist/treaty/index.d.ts"
|
|
40
25
|
},
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"homepage": "https://github.com/elysiajs/elysia-eden",
|
|
48
|
-
"repository": {
|
|
49
|
-
"type": "git",
|
|
50
|
-
"url": "https://github.com/elysiajs/elysia-eden"
|
|
26
|
+
"./fetch": {
|
|
27
|
+
"require": "./dist/fetch.js",
|
|
28
|
+
"import": "./dist/fetch.mjs",
|
|
29
|
+
"node": "./dist/fetch.js",
|
|
30
|
+
"default": "./dist/fetch.js",
|
|
31
|
+
"types": "./dist/fetch/index.d.ts"
|
|
51
32
|
},
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
33
|
+
"./fn": {
|
|
34
|
+
"require": "./dist/fn.js",
|
|
35
|
+
"import": "./dist/fn.mjs",
|
|
36
|
+
"node": "./dist/fn.js",
|
|
37
|
+
"default": "./dist/fn.js",
|
|
38
|
+
"types": "./dist/fn/index.d.ts"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"types": "./src/index.ts",
|
|
42
|
+
"keywords": [
|
|
43
|
+
"elysia",
|
|
44
|
+
"eden",
|
|
45
|
+
"connector"
|
|
46
|
+
],
|
|
47
|
+
"homepage": "https://github.com/elysiajs/elysia-eden",
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "https://github.com/elysiajs/elysia-eden"
|
|
51
|
+
},
|
|
52
|
+
"bugs": "https://github.com/elysiajs/elysia-eden/issues",
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"scripts": {
|
|
55
|
+
"dev": "bun run --hot example/index.ts",
|
|
56
|
+
"test": "bun wiptest",
|
|
57
|
+
"build": "vite build && tsc",
|
|
58
|
+
"release": "npm run build && npm run test && npm publish --access public"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"elysia": ">= 0.6.7"
|
|
62
|
+
},
|
|
63
|
+
"peerDependenciesMeta": {
|
|
64
|
+
"@sinclair/typebox": {
|
|
65
|
+
"optional": true
|
|
83
66
|
}
|
|
84
|
-
}
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@elysiajs/cors": "0.6.0",
|
|
70
|
+
"@elysiajs/fn": "^0.6.1",
|
|
71
|
+
"@sinclair/typebox": "^0.26.8",
|
|
72
|
+
"@types/node": "^18.15.5",
|
|
73
|
+
"elysia": "0.6.10",
|
|
74
|
+
"eslint": "^8.26.0",
|
|
75
|
+
"rimraf": "^4.4.1",
|
|
76
|
+
"typescript": "^5.0.4",
|
|
77
|
+
"vite": "^4.4.9",
|
|
78
|
+
"vite-plugin-dts": "^2.3.0"
|
|
79
|
+
},
|
|
80
|
+
"dependencies": {
|
|
81
|
+
"superjson": "^1.12.2"
|
|
82
|
+
},
|
|
83
|
+
"prettier": {
|
|
84
|
+
"semi": false,
|
|
85
|
+
"tabWidth": 4,
|
|
86
|
+
"singleQuote": true,
|
|
87
|
+
"trailingComma": "none"
|
|
88
|
+
}
|
|
89
|
+
}
|
package/src/fetch/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Elysia } from 'elysia'
|
|
2
2
|
|
|
3
|
-
import { EdenFetchError } from '../
|
|
3
|
+
import { EdenFetchError } from '../errors'
|
|
4
4
|
import type { EdenFetch } from './types'
|
|
5
5
|
export type { EdenFetch } from './types'
|
|
6
6
|
|
|
@@ -10,10 +10,10 @@ export const edenFetch =
|
|
|
10
10
|
config?: EdenFetch.Config
|
|
11
11
|
): EdenFetch.Create<App> =>
|
|
12
12
|
// @ts-ignore
|
|
13
|
-
|
|
13
|
+
(endpoint: string, { query, params, body, ...options } = {}) => {
|
|
14
14
|
if (params)
|
|
15
15
|
Object.entries(params).forEach(([key, value]) => {
|
|
16
|
-
endpoint = endpoint.replace(`:${key}`, value)
|
|
16
|
+
endpoint = endpoint.replace(`:${key}`, value as string)
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
const contentType = options.headers?.['Content-Type']
|
|
@@ -26,9 +26,12 @@ export const edenFetch =
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const fetch = config?.fetcher || globalThis.fetch
|
|
29
|
+
const queryStr = query
|
|
30
|
+
? `?${new URLSearchParams(query).toString()}`
|
|
31
|
+
: ''
|
|
29
32
|
|
|
30
33
|
// @ts-ignore
|
|
31
|
-
|
|
34
|
+
const execute = () => fetch(server + endpoint + queryStr, {
|
|
32
35
|
...options,
|
|
33
36
|
headers: body
|
|
34
37
|
? {
|
|
@@ -59,9 +62,20 @@ export const edenFetch =
|
|
|
59
62
|
if (res.status > 300)
|
|
60
63
|
return {
|
|
61
64
|
data: null,
|
|
65
|
+
status: res.status,
|
|
66
|
+
headers: res.headers,
|
|
67
|
+
retry: execute,
|
|
62
68
|
error: new EdenFetchError(res.status, data)
|
|
63
69
|
}
|
|
64
70
|
|
|
65
|
-
return {
|
|
71
|
+
return {
|
|
72
|
+
data,
|
|
73
|
+
error: null,
|
|
74
|
+
status: res.status,
|
|
75
|
+
headers: res.headers,
|
|
76
|
+
retry: execute
|
|
77
|
+
}
|
|
66
78
|
})
|
|
79
|
+
|
|
80
|
+
return execute()
|
|
67
81
|
}
|
package/src/fetch/types.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { Elysia } from 'elysia'
|
|
2
|
-
import type { EdenFetchError } from '../
|
|
2
|
+
import type { EdenFetchError } from '../errors'
|
|
3
3
|
import type { MapError, IsUnknown, IsNever } from '../types'
|
|
4
4
|
|
|
5
|
+
type Prettify<T> = {
|
|
6
|
+
[K in keyof T]: T[K]
|
|
7
|
+
} & {}
|
|
8
|
+
|
|
5
9
|
export namespace EdenFetch {
|
|
6
10
|
export type Create<App extends Elysia<any, any>> = App['meta'] extends {
|
|
7
11
|
schema: infer Schema extends Record<string, any>
|
|
@@ -34,6 +38,13 @@ export namespace EdenFetch {
|
|
|
34
38
|
: {
|
|
35
39
|
params: Route['params']
|
|
36
40
|
}) &
|
|
41
|
+
(IsNever<keyof Route['query']> extends true
|
|
42
|
+
? {
|
|
43
|
+
query?: Record<never, string>
|
|
44
|
+
}
|
|
45
|
+
: {
|
|
46
|
+
query: Route['query']
|
|
47
|
+
}) &
|
|
37
48
|
(undefined extends Route['headers']
|
|
38
49
|
? {
|
|
39
50
|
headers?: Record<string, string>
|
|
@@ -45,17 +56,25 @@ export namespace EdenFetch {
|
|
|
45
56
|
? { body: Route['body'] }
|
|
46
57
|
: { body?: unknown })
|
|
47
58
|
) => Promise<
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
Prettify<
|
|
60
|
+
(
|
|
61
|
+
| {
|
|
62
|
+
data: Awaited<Route['response']['200']>
|
|
63
|
+
error: null
|
|
64
|
+
}
|
|
65
|
+
| {
|
|
66
|
+
data: null
|
|
67
|
+
error: MapError<Route['response']> extends infer Errors
|
|
68
|
+
? IsNever<Errors> extends true
|
|
69
|
+
? EdenFetchError<number, string>
|
|
70
|
+
: Errors
|
|
71
|
+
: EdenFetchError<number, string>
|
|
72
|
+
}
|
|
73
|
+
) & {
|
|
74
|
+
status: number
|
|
75
|
+
response: Response
|
|
76
|
+
headers: Record<string, string>
|
|
77
|
+
}
|
|
78
|
+
>
|
|
60
79
|
>
|
|
61
80
|
}
|