@elysiajs/eden 0.5.6 → 0.6.1
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/.eslintrc +2 -0
- package/dist/fetch/index.d.ts +2 -1
- package/dist/fetch/index.d.ts.map +1 -0
- package/dist/fetch/types.d.ts +6 -2
- package/dist/fetch/types.d.ts.map +1 -0
- package/dist/fetch.js +1 -1
- package/dist/fetch.mjs +11 -11
- package/dist/fn/index.d.ts +2 -1
- package/dist/fn/index.d.ts.map +1 -0
- package/dist/fn/types.d.ts +7 -3
- package/dist/fn/types.d.ts.map +1 -0
- package/dist/fn/utils.d.ts +1 -0
- package/dist/fn/utils.d.ts.map +1 -0
- package/dist/fn.js +1 -1
- package/dist/fn.mjs +18 -18
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/treaty/index.d.ts +2 -3
- package/dist/treaty/index.d.ts.map +1 -0
- package/dist/treaty/utils.d.ts +1 -0
- package/dist/treaty/utils.d.ts.map +1 -0
- package/dist/treaty.js +1 -1
- package/dist/treaty.mjs +106 -87
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +79 -81
- package/src/fetch/index.ts +3 -1
- package/src/fetch/types.ts +8 -7
- package/src/fn/index.ts +1 -1
- package/src/fn/types.ts +6 -6
- package/src/fn/utils.ts +1 -0
- package/src/treaty/index.ts +56 -37
- package/src/treaty/types.ts +114 -140
- package/src/types.ts +0 -13
package/src/treaty/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Elysia,
|
|
1
|
+
import type { Elysia, AnyTypedSchema } from 'elysia'
|
|
2
2
|
|
|
3
3
|
import type { EdenWS } from './index'
|
|
4
4
|
import type { IsNever, IsUnknown, MapError, UnionToIntersect } from '../types'
|
|
@@ -10,27 +10,33 @@ type Replace<RecordType, TargetType, GenericType> = {
|
|
|
10
10
|
: RecordType[K]
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
type Files = File | FileList
|
|
15
|
+
|
|
13
16
|
export namespace EdenTreaty {
|
|
14
|
-
export type Create<App extends Elysia<any>> = App['meta'] extends
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
>
|
|
17
|
+
export type Create<App extends Elysia<any, any>> = App['meta'] extends {
|
|
18
|
+
schema: infer Schema extends Record<string, any>
|
|
19
|
+
}
|
|
18
20
|
? EdenTreaty.Sign<Schema>
|
|
19
21
|
: 'Please install Elysia before using Eden'
|
|
20
22
|
|
|
21
23
|
export interface Config {
|
|
24
|
+
/**
|
|
25
|
+
* Default options to pass to fetch
|
|
26
|
+
*/
|
|
27
|
+
$fetch?: FetchRequestInit
|
|
22
28
|
fetcher?: typeof fetch
|
|
23
29
|
}
|
|
24
30
|
|
|
25
31
|
export type Sign<A> = {
|
|
26
|
-
[Path in keyof A as Path extends `/${infer Prefix}/${
|
|
32
|
+
[Path in keyof A as Path extends `/${infer Prefix}/${string}`
|
|
27
33
|
? Prefix
|
|
28
34
|
: Path extends `/`
|
|
29
35
|
? 'index'
|
|
30
36
|
: Path extends `/${infer Prefix}`
|
|
31
37
|
? Prefix
|
|
32
38
|
: never]: UnionToIntersect<
|
|
33
|
-
Path extends `/${
|
|
39
|
+
Path extends `/${string}/${infer Rest}`
|
|
34
40
|
? NestPath<
|
|
35
41
|
Rest,
|
|
36
42
|
{
|
|
@@ -43,71 +49,45 @@ export namespace EdenTreaty {
|
|
|
43
49
|
: (params: {
|
|
44
50
|
$query: Route['query']
|
|
45
51
|
}) => EdenWS<Route>
|
|
46
|
-
:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
| {
|
|
86
|
-
data: null
|
|
87
|
-
error: MapError<
|
|
88
|
-
Route['response']
|
|
89
|
-
> extends infer Errors
|
|
90
|
-
? IsNever<Errors> extends true
|
|
91
|
-
? EdenFetchError<
|
|
92
|
-
number,
|
|
93
|
-
string
|
|
94
|
-
>
|
|
95
|
-
: Errors
|
|
96
|
-
: EdenFetchError<
|
|
97
|
-
number,
|
|
98
|
-
string
|
|
99
|
-
>
|
|
100
|
-
}
|
|
101
|
-
>
|
|
102
|
-
: (
|
|
103
|
-
params: Replace<
|
|
104
|
-
Route['body'],
|
|
105
|
-
Blob | Blob[],
|
|
106
|
-
File | FileList
|
|
107
|
-
> & {
|
|
108
|
-
$query?: Route['query']
|
|
109
|
-
$fetch?: RequestInit
|
|
110
|
-
}
|
|
52
|
+
: ((
|
|
53
|
+
params: (IsUnknown<
|
|
54
|
+
Route['body']
|
|
55
|
+
> extends false
|
|
56
|
+
? Replace<
|
|
57
|
+
Route['body'],
|
|
58
|
+
Blob | Blob[],
|
|
59
|
+
Files
|
|
60
|
+
>
|
|
61
|
+
: {}) &
|
|
62
|
+
(undefined extends Route['query']
|
|
63
|
+
? {
|
|
64
|
+
$query?: Record<
|
|
65
|
+
string,
|
|
66
|
+
string
|
|
67
|
+
>
|
|
68
|
+
}
|
|
69
|
+
: {
|
|
70
|
+
$query: Route['query']
|
|
71
|
+
}) &
|
|
72
|
+
(undefined extends Route['headers']
|
|
73
|
+
? {
|
|
74
|
+
$headers?: Record<
|
|
75
|
+
string,
|
|
76
|
+
unknown
|
|
77
|
+
>
|
|
78
|
+
}
|
|
79
|
+
: {
|
|
80
|
+
$headers: Route['headers']
|
|
81
|
+
}) &
|
|
82
|
+
(IsUnknown<
|
|
83
|
+
Route['params']
|
|
84
|
+
> extends false
|
|
85
|
+
? {
|
|
86
|
+
$params?: never
|
|
87
|
+
}
|
|
88
|
+
: {
|
|
89
|
+
$params: Route['params']
|
|
90
|
+
})
|
|
111
91
|
) => Promise<
|
|
112
92
|
| {
|
|
113
93
|
data: Route['response'] extends {
|
|
@@ -133,7 +113,17 @@ export namespace EdenTreaty {
|
|
|
133
113
|
string
|
|
134
114
|
>
|
|
135
115
|
}
|
|
136
|
-
>
|
|
116
|
+
>) extends (
|
|
117
|
+
params: infer Params
|
|
118
|
+
) => infer Response
|
|
119
|
+
? {
|
|
120
|
+
$params: undefined
|
|
121
|
+
$headers: undefined
|
|
122
|
+
$query: undefined
|
|
123
|
+
} extends Params
|
|
124
|
+
? (params?: Params) => Response
|
|
125
|
+
: (params: Params) => Response
|
|
126
|
+
: never
|
|
137
127
|
: never
|
|
138
128
|
}
|
|
139
129
|
>
|
|
@@ -147,71 +137,45 @@ export namespace EdenTreaty {
|
|
|
147
137
|
: (params: {
|
|
148
138
|
$query: Route['query']
|
|
149
139
|
}) => EdenWS<Route>
|
|
150
|
-
:
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
| {
|
|
190
|
-
data: null
|
|
191
|
-
error: MapError<
|
|
192
|
-
Route['response']
|
|
193
|
-
> extends infer Errors
|
|
194
|
-
? IsNever<Errors> extends true
|
|
195
|
-
? EdenFetchError<
|
|
196
|
-
number,
|
|
197
|
-
string
|
|
198
|
-
>
|
|
199
|
-
: Errors
|
|
200
|
-
: EdenFetchError<
|
|
201
|
-
number,
|
|
202
|
-
string
|
|
203
|
-
>
|
|
204
|
-
}
|
|
205
|
-
>
|
|
206
|
-
: (
|
|
207
|
-
params: Replace<
|
|
208
|
-
Route['body'],
|
|
209
|
-
Blob | Blob[],
|
|
210
|
-
File | FileList
|
|
211
|
-
> & {
|
|
212
|
-
$query?: Route['query']
|
|
213
|
-
$fetch?: RequestInit
|
|
214
|
-
}
|
|
140
|
+
: ((
|
|
141
|
+
params: (IsUnknown<
|
|
142
|
+
Route['body']
|
|
143
|
+
> extends false
|
|
144
|
+
? Replace<
|
|
145
|
+
Route['body'],
|
|
146
|
+
Blob | Blob[],
|
|
147
|
+
Files
|
|
148
|
+
>
|
|
149
|
+
: {}) &
|
|
150
|
+
(undefined extends Route['query']
|
|
151
|
+
? {
|
|
152
|
+
$query?: Record<
|
|
153
|
+
string,
|
|
154
|
+
string
|
|
155
|
+
>
|
|
156
|
+
}
|
|
157
|
+
: {
|
|
158
|
+
$query: Route['query']
|
|
159
|
+
}) &
|
|
160
|
+
(undefined extends Route['headers']
|
|
161
|
+
? {
|
|
162
|
+
$headers?: Record<
|
|
163
|
+
string,
|
|
164
|
+
unknown
|
|
165
|
+
>
|
|
166
|
+
}
|
|
167
|
+
: {
|
|
168
|
+
$headers: Route['headers']
|
|
169
|
+
}) &
|
|
170
|
+
(IsUnknown<
|
|
171
|
+
Route['params']
|
|
172
|
+
> extends false
|
|
173
|
+
? {
|
|
174
|
+
$params?: never
|
|
175
|
+
}
|
|
176
|
+
: {
|
|
177
|
+
$params: Route['params']
|
|
178
|
+
})
|
|
215
179
|
) => Promise<
|
|
216
180
|
| {
|
|
217
181
|
data: Route['response'] extends {
|
|
@@ -234,7 +198,17 @@ export namespace EdenTreaty {
|
|
|
234
198
|
: Errors
|
|
235
199
|
: EdenFetchError<number, string>
|
|
236
200
|
}
|
|
237
|
-
>
|
|
201
|
+
>) extends (
|
|
202
|
+
params: infer Params
|
|
203
|
+
) => infer Response
|
|
204
|
+
? {
|
|
205
|
+
$params: undefined
|
|
206
|
+
$headers: undefined
|
|
207
|
+
$query: undefined
|
|
208
|
+
} extends Params
|
|
209
|
+
? (params?: Params) => Response
|
|
210
|
+
: (params: Params) => Response
|
|
211
|
+
: never
|
|
238
212
|
: never
|
|
239
213
|
}
|
|
240
214
|
>
|
|
@@ -261,6 +235,6 @@ type NestPath<T extends string, V> = T extends `${infer First}/${infer Rest}`
|
|
|
261
235
|
? First extends `:${infer Parameter}`
|
|
262
236
|
? Record<(string & {}) | number | `:${Parameter}`, NestPath<Rest, V>>
|
|
263
237
|
: Record<First, NestPath<Rest, V>>
|
|
264
|
-
: T extends `:${
|
|
238
|
+
: T extends `:${string}`
|
|
265
239
|
? Record<(string & {}) | number | T, V>
|
|
266
240
|
: Record<T, V>
|
package/src/types.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Elysia,
|
|
3
|
-
SCHEMA,
|
|
4
|
-
IsPathParameter,
|
|
5
|
-
EXPOSED,
|
|
6
|
-
AnyTypedSchema
|
|
7
|
-
} from 'elysia'
|
|
8
|
-
|
|
9
1
|
import type { EdenFetchError } from './utils'
|
|
10
2
|
|
|
11
3
|
// https://stackoverflow.com/a/39495173
|
|
@@ -33,11 +25,6 @@ export type MapError<T extends Record<number, unknown>> = [
|
|
|
33
25
|
}[A]
|
|
34
26
|
: false
|
|
35
27
|
|
|
36
|
-
// https://twitter.com/mattpocockuk/status/1622730173446557697?s=20
|
|
37
|
-
type Prettify<T> = {
|
|
38
|
-
[K in keyof T]: T[K]
|
|
39
|
-
} & {}
|
|
40
|
-
|
|
41
28
|
export type UnionToIntersect<U> = (
|
|
42
29
|
U extends unknown ? (arg: U) => 0 : never
|
|
43
30
|
) extends (arg: infer I) => 0
|