spiceflow 1.1.7 → 1.1.9
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/README.md +177 -92
- package/dist/benchmark.benchmark.js.map +1 -1
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js.map +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +8 -12
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/utils.js.map +1 -1
- package/dist/client/ws.d.ts.map +1 -1
- package/dist/client/ws.js +1 -3
- package/dist/client/ws.js.map +1 -1
- package/dist/client.test.js.map +1 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/cors.d.ts.map +1 -1
- package/dist/cors.js.map +1 -1
- package/dist/cors.test.js.map +1 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js.map +1 -1
- package/dist/middleware.test.js +65 -0
- package/dist/middleware.test.js.map +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +1 -1
- package/dist/openapi.js.map +1 -1
- package/dist/openapi.test.js.map +1 -1
- package/dist/spiceflow.d.ts.map +1 -1
- package/dist/spiceflow.js +12 -5
- package/dist/spiceflow.js.map +1 -1
- package/dist/spiceflow.test.js.map +1 -1
- package/dist/stream.test.js +6 -6
- package/dist/stream.test.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/types.test.js +56 -6
- package/dist/types.test.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/dist/zod.test.js.map +1 -1
- package/package.json +1 -1
- package/src/benchmark.benchmark.ts +8 -8
- package/src/client/errors.ts +17 -17
- package/src/client/index.ts +437 -469
- package/src/client/types.ts +168 -191
- package/src/client/utils.ts +5 -5
- package/src/client/ws.ts +87 -89
- package/src/client.test.ts +176 -183
- package/src/context.ts +82 -82
- package/src/cors.test.ts +38 -38
- package/src/cors.ts +87 -92
- package/src/error.ts +13 -13
- package/src/middleware.test.ts +221 -149
- package/src/openapi.test.ts +97 -97
- package/src/openapi.ts +365 -365
- package/src/spiceflow.test.ts +461 -467
- package/src/spiceflow.ts +1117 -1157
- package/src/stream.test.ts +310 -310
- package/src/types.test.ts +59 -39
- package/src/types.ts +698 -701
- package/src/utils.ts +79 -79
- package/src/zod.test.ts +64 -64
package/src/types.ts
CHANGED
|
@@ -5,11 +5,11 @@ import z from 'zod'
|
|
|
5
5
|
import type { BunFile, Server } from 'bun'
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
OptionalKind,
|
|
9
|
+
Static,
|
|
10
|
+
StaticDecode,
|
|
11
|
+
TObject,
|
|
12
|
+
TSchema,
|
|
13
13
|
} from '@sinclair/typebox'
|
|
14
14
|
|
|
15
15
|
import type { OpenAPIV3 } from 'openapi-types'
|
|
@@ -17,10 +17,10 @@ import type { OpenAPIV3 } from 'openapi-types'
|
|
|
17
17
|
import { ZodObject, ZodTypeAny } from 'zod'
|
|
18
18
|
import type { Context, ErrorContext, MiddlewareContext } from './context.js'
|
|
19
19
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
ELYSIA_RESPONSE,
|
|
21
|
+
InternalServerError,
|
|
22
|
+
ParseError,
|
|
23
|
+
ValidationError,
|
|
24
24
|
} from './error.js'
|
|
25
25
|
import { Spiceflow } from './spiceflow.js'
|
|
26
26
|
|
|
@@ -30,145 +30,146 @@ export type MaybePromise<T> = T | Promise<T>
|
|
|
30
30
|
export type ObjectValues<T extends object> = T[keyof T]
|
|
31
31
|
|
|
32
32
|
type IsPathParameter<Part extends string> = Part extends `:${infer Parameter}`
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
? Parameter
|
|
34
|
+
: Part extends `*`
|
|
35
|
+
? '*'
|
|
36
|
+
: never
|
|
37
37
|
|
|
38
38
|
export type GetPathParameter<Path extends string> =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
Path extends `${infer A}/${infer B}`
|
|
40
|
+
? IsPathParameter<A> | GetPathParameter<B>
|
|
41
|
+
: IsPathParameter<Path>
|
|
42
42
|
|
|
43
43
|
export type ResolvePath<Path extends string> = Prettify<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
{
|
|
45
|
+
[Param in GetPathParameter<Path> as Param extends `${string}?`
|
|
46
|
+
? never
|
|
47
|
+
: Param]: string
|
|
48
|
+
} & {
|
|
49
|
+
[Param in GetPathParameter<Path> as Param extends `${infer OptionalParam}?`
|
|
50
|
+
? OptionalParam
|
|
51
|
+
: never]?: string
|
|
52
|
+
}
|
|
53
53
|
>
|
|
54
54
|
|
|
55
55
|
// https://twitter.com/mattpocockuk/status/1622730173446557697?s=20
|
|
56
56
|
export type Prettify<T> = {
|
|
57
|
-
|
|
57
|
+
[K in keyof T]: T[K]
|
|
58
58
|
} & {}
|
|
59
59
|
|
|
60
60
|
export type Prettify2<T> = {
|
|
61
|
-
|
|
61
|
+
[K in keyof T]: Prettify<T[K]>
|
|
62
62
|
} & {}
|
|
63
63
|
|
|
64
64
|
export type Partial2<T> = {
|
|
65
|
-
|
|
65
|
+
[K in keyof T]?: Partial<T[K]>
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
export type NeverKey<T> = {
|
|
69
|
-
|
|
69
|
+
[K in keyof T]?: T[K]
|
|
70
70
|
} & {}
|
|
71
71
|
|
|
72
|
-
type IsBothObject<A, B> =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
type IsBothObject<A, B> =
|
|
73
|
+
A extends Record<string | number | symbol, unknown>
|
|
74
|
+
? B extends Record<string | number | symbol, unknown>
|
|
75
|
+
? IsClass<A> extends false
|
|
76
|
+
? IsClass<B> extends false
|
|
77
|
+
? true
|
|
78
|
+
: false
|
|
79
|
+
: false
|
|
80
|
+
: false
|
|
81
|
+
: false
|
|
81
82
|
|
|
82
83
|
type IsClass<V> = V extends abstract new (...args: any) => any ? true : false
|
|
83
84
|
type And<A, B> = A extends true ? (B extends true ? true : false) : false
|
|
84
85
|
|
|
85
86
|
export type Reconcile<
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
A extends Object,
|
|
88
|
+
B extends Object,
|
|
89
|
+
Override extends boolean = false,
|
|
90
|
+
// Detect Stack limit, eg. circular dependency
|
|
91
|
+
Stack extends number[] = [],
|
|
91
92
|
> = Stack['length'] extends 16
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
93
|
+
? A
|
|
94
|
+
: Override extends true
|
|
95
|
+
? {
|
|
96
|
+
[key in keyof A as key extends keyof B ? never : key]: A[key]
|
|
97
|
+
} extends infer Collision
|
|
98
|
+
? {} extends Collision
|
|
99
|
+
? {
|
|
100
|
+
[key in keyof B]: IsBothObject<
|
|
101
|
+
// @ts-ignore trust me bro
|
|
102
|
+
A[key],
|
|
103
|
+
B[key]
|
|
104
|
+
> extends true
|
|
105
|
+
? Reconcile<
|
|
106
|
+
// @ts-ignore trust me bro
|
|
107
|
+
A[key],
|
|
108
|
+
B[key],
|
|
109
|
+
Override,
|
|
110
|
+
[0, ...Stack]
|
|
111
|
+
>
|
|
112
|
+
: B[key]
|
|
113
|
+
}
|
|
114
|
+
: Prettify<
|
|
115
|
+
Collision & {
|
|
116
|
+
[key in keyof B]: B[key]
|
|
117
|
+
}
|
|
118
|
+
>
|
|
119
|
+
: never
|
|
120
|
+
: {
|
|
121
|
+
[key in keyof B as key extends keyof A ? never : key]: B[key]
|
|
122
|
+
} extends infer Collision
|
|
123
|
+
? {} extends Collision
|
|
124
|
+
? {
|
|
125
|
+
[key in keyof A]: IsBothObject<
|
|
126
|
+
A[key],
|
|
127
|
+
// @ts-ignore trust me bro
|
|
128
|
+
B[key]
|
|
129
|
+
> extends true
|
|
130
|
+
? Reconcile<
|
|
131
|
+
// @ts-ignore trust me bro
|
|
132
|
+
A[key],
|
|
133
|
+
// @ts-ignore trust me bro
|
|
134
|
+
B[key],
|
|
135
|
+
Override,
|
|
136
|
+
[0, ...Stack]
|
|
137
|
+
>
|
|
138
|
+
: A[key]
|
|
139
|
+
}
|
|
140
|
+
: Prettify<
|
|
141
|
+
{
|
|
142
|
+
[key in keyof A]: A[key]
|
|
143
|
+
} & Collision
|
|
144
|
+
>
|
|
145
|
+
: never
|
|
145
146
|
|
|
146
147
|
export interface SingletonBase {
|
|
147
|
-
|
|
148
|
+
state: Record<string, unknown>
|
|
148
149
|
}
|
|
149
150
|
|
|
150
151
|
export interface DefinitionBase {
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
type: Record<string, unknown>
|
|
153
|
+
error: Record<string, Error>
|
|
153
154
|
}
|
|
154
155
|
|
|
155
156
|
export type RouteBase = Record<string, unknown>
|
|
156
157
|
|
|
157
158
|
export interface MetadataBase {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
schema: RouteSchema
|
|
160
|
+
macro: BaseMacro
|
|
161
|
+
macroFn: BaseMacroFn
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
export interface RouteSchema {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
body?: unknown
|
|
166
|
+
query?: unknown
|
|
167
|
+
params?: unknown
|
|
168
|
+
response?: unknown
|
|
168
169
|
}
|
|
169
170
|
|
|
170
171
|
type OptionalField = {
|
|
171
|
-
|
|
172
|
+
[OptionalKind]: 'Optional'
|
|
172
173
|
}
|
|
173
174
|
|
|
174
175
|
export type TypeSchema = TSchema | ZodTypeAny
|
|
@@ -176,320 +177,319 @@ export type TypeSchema = TSchema | ZodTypeAny
|
|
|
176
177
|
export type TypeObject = TObject | ZodObject<any, any, any>
|
|
177
178
|
|
|
178
179
|
export type UnwrapSchema<
|
|
179
|
-
|
|
180
|
-
|
|
180
|
+
Schema extends TypeSchema | string | undefined,
|
|
181
|
+
Definitions extends Record<string, unknown> = {},
|
|
181
182
|
> = undefined extends Schema
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
183
|
+
? unknown
|
|
184
|
+
: Schema extends ZodTypeAny
|
|
185
|
+
? z.infer<Schema>
|
|
186
|
+
: Schema extends TSchema
|
|
187
|
+
? Schema extends OptionalField
|
|
188
|
+
? Prettify<Partial<Static<Schema>>>
|
|
189
|
+
: StaticDecode<Schema>
|
|
190
|
+
: Schema extends string
|
|
191
|
+
? Definitions extends Record<Schema, infer NamedSchema>
|
|
192
|
+
? NamedSchema
|
|
193
|
+
: Definitions
|
|
194
|
+
: unknown
|
|
194
195
|
|
|
195
196
|
export interface UnwrapRoute<
|
|
196
|
-
|
|
197
|
-
|
|
197
|
+
in out Schema extends InputSchema<any>,
|
|
198
|
+
in out Definitions extends DefinitionBase['type'] = {},
|
|
198
199
|
> {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
200
|
+
body: UnwrapSchema<Schema['body'], Definitions>
|
|
201
|
+
query: UnwrapSchema<Schema['query'], Definitions>
|
|
202
|
+
params: UnwrapSchema<Schema['params'], Definitions>
|
|
203
|
+
response: Schema['response'] extends TypeSchema | string
|
|
204
|
+
? {
|
|
205
|
+
200: CoExist<
|
|
206
|
+
UnwrapSchema<Schema['response'], Definitions>,
|
|
207
|
+
File,
|
|
208
|
+
BunFile
|
|
209
|
+
>
|
|
210
|
+
}
|
|
211
|
+
: Schema['response'] extends Record<number, TypeSchema | string>
|
|
212
|
+
? {
|
|
213
|
+
[k in keyof Schema['response']]: CoExist<
|
|
214
|
+
UnwrapSchema<Schema['response'][k], Definitions>,
|
|
215
|
+
File,
|
|
216
|
+
BunFile
|
|
217
|
+
>
|
|
218
|
+
}
|
|
219
|
+
: unknown | void
|
|
219
220
|
}
|
|
220
221
|
|
|
221
222
|
export type LifeCycleEvent =
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
223
|
+
| 'start'
|
|
224
|
+
| 'request'
|
|
225
|
+
| 'parse'
|
|
226
|
+
| 'transform'
|
|
227
|
+
| 'beforeHandle'
|
|
228
|
+
| 'afterHandle'
|
|
229
|
+
| 'response'
|
|
230
|
+
| 'error'
|
|
231
|
+
| 'stop'
|
|
231
232
|
|
|
232
233
|
export type ContentType = MaybeArray<
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
234
|
+
| (string & {})
|
|
235
|
+
| 'none'
|
|
236
|
+
| 'text'
|
|
237
|
+
| 'json'
|
|
238
|
+
| 'formdata'
|
|
239
|
+
| 'urlencoded'
|
|
240
|
+
| 'arrayBuffer'
|
|
241
|
+
| 'text/plain'
|
|
242
|
+
| 'application/json'
|
|
243
|
+
| 'multipart/form-data'
|
|
244
|
+
| 'application/x-www-form-urlencoded'
|
|
244
245
|
>
|
|
245
246
|
|
|
246
247
|
export type HTTPMethod =
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
248
|
+
| (string & {})
|
|
249
|
+
| 'ACL'
|
|
250
|
+
| 'BIND'
|
|
251
|
+
| 'CHECKOUT'
|
|
252
|
+
| 'CONNECT'
|
|
253
|
+
| 'COPY'
|
|
254
|
+
| 'DELETE'
|
|
255
|
+
| 'GET'
|
|
256
|
+
| 'HEAD'
|
|
257
|
+
| 'LINK'
|
|
258
|
+
| 'LOCK'
|
|
259
|
+
| 'M-SEARCH'
|
|
260
|
+
| 'MERGE'
|
|
261
|
+
| 'MKACTIVITY'
|
|
262
|
+
| 'MKCALENDAR'
|
|
263
|
+
| 'MKCOL'
|
|
264
|
+
| 'MOVE'
|
|
265
|
+
| 'NOTIFY'
|
|
266
|
+
| 'OPTIONS'
|
|
267
|
+
| 'PATCH'
|
|
268
|
+
| 'POST'
|
|
269
|
+
| 'PROPFIND'
|
|
270
|
+
| 'PROPPATCH'
|
|
271
|
+
| 'PURGE'
|
|
272
|
+
| 'PUT'
|
|
273
|
+
| 'REBIND'
|
|
274
|
+
| 'REPORT'
|
|
275
|
+
| 'SEARCH'
|
|
276
|
+
| 'SOURCE'
|
|
277
|
+
| 'SUBSCRIBE'
|
|
278
|
+
| 'TRACE'
|
|
279
|
+
| 'UNBIND'
|
|
280
|
+
| 'UNLINK'
|
|
281
|
+
| 'UNLOCK'
|
|
282
|
+
| 'UNSUBSCRIBE'
|
|
283
|
+
| 'ALL'
|
|
283
284
|
|
|
284
285
|
export interface InputSchema<Name extends string = string> {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
286
|
+
body?: TypeSchema | Name
|
|
287
|
+
query?: TypeObject | Name
|
|
288
|
+
params?: TypeObject | Name
|
|
289
|
+
response?:
|
|
290
|
+
| TypeSchema
|
|
291
|
+
| Record<number, TypeSchema>
|
|
292
|
+
| Name
|
|
293
|
+
| Record<number, Name | TypeSchema>
|
|
293
294
|
}
|
|
294
295
|
|
|
295
296
|
export interface MergeSchema<
|
|
296
|
-
|
|
297
|
-
|
|
297
|
+
in out A extends RouteSchema,
|
|
298
|
+
in out B extends RouteSchema,
|
|
298
299
|
> {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
300
|
+
body: undefined extends A['body'] ? B['body'] : A['body']
|
|
301
|
+
query: undefined extends A['query'] ? B['query'] : A['query']
|
|
302
|
+
params: undefined extends A['params'] ? B['params'] : A['params']
|
|
303
|
+
response: {} extends A['response']
|
|
304
|
+
? {} extends B['response']
|
|
305
|
+
? {}
|
|
306
|
+
: B['response']
|
|
307
|
+
: {} extends B['response']
|
|
308
|
+
? A['response']
|
|
309
|
+
: A['response'] & Omit<B['response'], keyof A['response']>
|
|
309
310
|
}
|
|
310
311
|
|
|
311
312
|
export type Handler<
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
313
|
+
in out Route extends RouteSchema = {},
|
|
314
|
+
in out Singleton extends SingletonBase = {
|
|
315
|
+
state: {}
|
|
316
|
+
},
|
|
317
|
+
Path extends string = '',
|
|
317
318
|
> = (
|
|
318
|
-
|
|
319
|
+
context: Context<Route, Singleton, Path>,
|
|
319
320
|
) => MaybePromise<
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
321
|
+
{} extends Route['response']
|
|
322
|
+
? unknown
|
|
323
|
+
: Route['response'][keyof Route['response']]
|
|
323
324
|
>
|
|
324
325
|
|
|
325
|
-
export type Replace<Original, Target, With> =
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
: Original
|
|
326
|
+
export type Replace<Original, Target, With> =
|
|
327
|
+
IsAny<Target> extends true
|
|
328
|
+
? Original
|
|
329
|
+
: Original extends Record<string, unknown>
|
|
330
|
+
? {
|
|
331
|
+
[K in keyof Original]: Original[K] extends Target ? With : Original[K]
|
|
332
|
+
}
|
|
333
|
+
: Original extends Target
|
|
334
|
+
? With
|
|
335
|
+
: Original
|
|
336
336
|
|
|
337
337
|
export type IsAny<T> = 0 extends 1 & T ? true : false
|
|
338
338
|
|
|
339
|
-
export type CoExist<Original, Target, With> =
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
339
|
+
export type CoExist<Original, Target, With> =
|
|
340
|
+
IsAny<Target> extends true
|
|
341
|
+
? Original
|
|
342
|
+
: Original extends Record<string, unknown>
|
|
343
|
+
? {
|
|
344
|
+
[K in keyof Original]: Original[K] extends Target
|
|
345
|
+
? Original[K] | With
|
|
346
|
+
: Original[K]
|
|
347
|
+
}
|
|
348
|
+
: Original extends Target
|
|
349
|
+
? Original | With
|
|
350
|
+
: Original
|
|
350
351
|
|
|
351
352
|
export type InlineHandler<
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
353
|
+
Route extends RouteSchema = {},
|
|
354
|
+
Singleton extends SingletonBase = {
|
|
355
|
+
state: {}
|
|
356
|
+
},
|
|
357
|
+
Path extends string = '',
|
|
358
|
+
MacroContext = {},
|
|
358
359
|
> = (
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
360
|
+
context: MacroContext extends Record<string | number | symbol, unknown>
|
|
361
|
+
? Prettify<MacroContext & Context<Route, Singleton, Path>>
|
|
362
|
+
: Context<Route, Singleton, Path>,
|
|
362
363
|
) =>
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
}[keyof Route['response']]
|
|
381
|
-
>
|
|
364
|
+
| Response
|
|
365
|
+
| MaybePromise<
|
|
366
|
+
{} extends Route['response']
|
|
367
|
+
? unknown
|
|
368
|
+
:
|
|
369
|
+
| (Route['response'] extends { 200: any }
|
|
370
|
+
? Route['response']
|
|
371
|
+
: string | number | boolean | Object)
|
|
372
|
+
| Route['response'][keyof Route['response']]
|
|
373
|
+
| {
|
|
374
|
+
[Status in keyof Route['response']]: {
|
|
375
|
+
_type: Record<Status, Route['response'][Status]>
|
|
376
|
+
[ELYSIA_RESPONSE]: Status
|
|
377
|
+
}
|
|
378
|
+
}[keyof Route['response']]
|
|
379
|
+
>
|
|
382
380
|
|
|
383
381
|
export type OptionalHandler<
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
> =
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
382
|
+
in out Route extends RouteSchema = {},
|
|
383
|
+
in out Singleton extends SingletonBase = {
|
|
384
|
+
state: {}
|
|
385
|
+
},
|
|
386
|
+
Path extends string = '',
|
|
387
|
+
> =
|
|
388
|
+
Handler<Route, Singleton, Path> extends (
|
|
389
|
+
context: infer Context,
|
|
390
|
+
) => infer Returned
|
|
391
|
+
? (context: Context) => Returned | MaybePromise<void>
|
|
392
|
+
: never
|
|
394
393
|
|
|
395
394
|
export type AfterHandler<
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
> =
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
395
|
+
in out Route extends RouteSchema = {},
|
|
396
|
+
in out Singleton extends SingletonBase = {
|
|
397
|
+
state: {}
|
|
398
|
+
},
|
|
399
|
+
Path extends string = '',
|
|
400
|
+
> =
|
|
401
|
+
Handler<Route, Singleton, Path> extends (
|
|
402
|
+
context: infer Context,
|
|
403
|
+
) => infer Returned
|
|
404
|
+
? (
|
|
405
|
+
context: Prettify<
|
|
406
|
+
{
|
|
407
|
+
response: Route['response']
|
|
408
|
+
} & Context
|
|
409
|
+
>,
|
|
410
|
+
) => Returned | MaybePromise<void>
|
|
411
|
+
: never
|
|
412
412
|
|
|
413
413
|
export type MapResponse<
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
414
|
+
in out Route extends RouteSchema = {},
|
|
415
|
+
in out Singleton extends SingletonBase = {
|
|
416
|
+
state: {}
|
|
417
|
+
},
|
|
418
|
+
Path extends string = '',
|
|
419
419
|
> = Handler<
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
420
|
+
Omit<Route, 'response'> & {
|
|
421
|
+
response: MaybePromise<Response | undefined | unknown>
|
|
422
|
+
},
|
|
423
|
+
Singleton & {
|
|
424
|
+
derive: {
|
|
425
|
+
response: Route['response']
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
Path
|
|
429
429
|
>
|
|
430
430
|
|
|
431
431
|
export type VoidHandler<
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
432
|
+
in out Route extends RouteSchema = {},
|
|
433
|
+
in out Singleton extends SingletonBase = {
|
|
434
|
+
state: {}
|
|
435
|
+
},
|
|
436
436
|
> = (context: Context<Route, Singleton>) => MaybePromise<void>
|
|
437
437
|
|
|
438
438
|
export type TransformHandler<
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
439
|
+
in out Route extends RouteSchema = {},
|
|
440
|
+
in out Singleton extends SingletonBase = {
|
|
441
|
+
state: {}
|
|
442
|
+
},
|
|
443
|
+
BasePath extends string = '',
|
|
444
444
|
> = {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
445
|
+
(
|
|
446
|
+
context: Prettify<
|
|
447
|
+
Context<
|
|
448
|
+
Route,
|
|
449
|
+
Omit<Singleton, 'resolve'> & {
|
|
450
|
+
resolve: {}
|
|
451
|
+
},
|
|
452
|
+
BasePath
|
|
453
|
+
>
|
|
454
|
+
>,
|
|
455
|
+
): MaybePromise<void>
|
|
456
456
|
}
|
|
457
457
|
|
|
458
458
|
export type BodyHandler<
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
459
|
+
in out Route extends RouteSchema = {},
|
|
460
|
+
in out Singleton extends SingletonBase = {
|
|
461
|
+
state: {}
|
|
462
|
+
},
|
|
463
|
+
Path extends string = '',
|
|
464
464
|
> = (
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
465
|
+
context: Prettify<
|
|
466
|
+
{
|
|
467
|
+
contentType: string
|
|
468
|
+
} & Context<Route, Singleton, Path>
|
|
469
|
+
>,
|
|
470
470
|
|
|
471
|
-
|
|
471
|
+
contentType: string,
|
|
472
472
|
) => MaybePromise<any>
|
|
473
473
|
|
|
474
474
|
export type MiddlewareHandler<
|
|
475
|
-
|
|
476
|
-
|
|
475
|
+
in out Route extends RouteSchema = {},
|
|
476
|
+
in out Singleton extends SingletonBase = any,
|
|
477
477
|
> = (
|
|
478
|
-
|
|
479
|
-
|
|
478
|
+
context: MiddlewareContext<Singleton>,
|
|
479
|
+
next: () => Promise<Response>,
|
|
480
480
|
) => MaybePromise<Route['response'] | void>
|
|
481
481
|
|
|
482
482
|
export type AfterResponseHandler<
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
483
|
+
in out Route extends RouteSchema = {},
|
|
484
|
+
in out Singleton extends SingletonBase = {
|
|
485
|
+
state: {}
|
|
486
|
+
},
|
|
487
487
|
> = (
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
488
|
+
context: Prettify<
|
|
489
|
+
Context<Route, Singleton> & {
|
|
490
|
+
response: Route['response']
|
|
491
|
+
}
|
|
492
|
+
>,
|
|
493
493
|
) => MaybePromise<void>
|
|
494
494
|
|
|
495
495
|
// export type GracefulHandler<
|
|
@@ -497,406 +497,403 @@ export type AfterResponseHandler<
|
|
|
497
497
|
// > = (data: Instance) => any
|
|
498
498
|
|
|
499
499
|
export type ErrorHandler<
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
500
|
+
in out T extends Record<string, Error> = {},
|
|
501
|
+
in out Route extends RouteSchema = {},
|
|
502
|
+
in out Singleton extends SingletonBase = {
|
|
503
|
+
state: {}
|
|
504
|
+
},
|
|
505
505
|
> = (
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
506
|
+
context: ErrorContext<
|
|
507
|
+
Route,
|
|
508
|
+
{
|
|
509
|
+
state: Singleton['state']
|
|
510
|
+
}
|
|
511
|
+
> &
|
|
512
|
+
(
|
|
513
|
+
| Prettify<
|
|
514
|
+
{
|
|
515
|
+
request: Request
|
|
516
|
+
code: 'UNKNOWN'
|
|
517
|
+
error: Readonly<Error>
|
|
518
|
+
} & Partial<Singleton['state']>
|
|
519
|
+
>
|
|
520
|
+
| Prettify<
|
|
521
|
+
{
|
|
522
|
+
request: Request
|
|
523
|
+
code: 'VALIDATION'
|
|
524
|
+
error: Readonly<ValidationError>
|
|
525
|
+
} & Singleton['state']
|
|
526
|
+
>
|
|
527
|
+
// | Prettify<
|
|
528
|
+
// {
|
|
529
|
+
// request: Request
|
|
530
|
+
// code: 'NOT_FOUND'
|
|
531
|
+
// error: Readonly<NotFoundError>
|
|
532
|
+
// } & NeverKey<Singleton['state']>
|
|
533
|
+
// >
|
|
534
|
+
| Prettify<
|
|
535
|
+
{
|
|
536
|
+
request: Request
|
|
537
|
+
code: 'PARSE'
|
|
538
|
+
error: Readonly<ParseError>
|
|
539
|
+
} & Singleton['state']
|
|
540
|
+
>
|
|
541
|
+
| Prettify<
|
|
542
|
+
{
|
|
543
|
+
request: Request
|
|
544
|
+
code: 'INTERNAL_SERVER_ERROR'
|
|
545
|
+
error: Readonly<InternalServerError>
|
|
546
|
+
} & Partial<Singleton['state']>
|
|
547
|
+
>
|
|
548
|
+
| Prettify<
|
|
549
|
+
{
|
|
550
|
+
[K in keyof T]: {
|
|
551
|
+
request: Request
|
|
552
|
+
code: K
|
|
553
|
+
error: Readonly<T[K]>
|
|
554
|
+
}
|
|
555
|
+
}[keyof T] &
|
|
556
|
+
Partial<Singleton['state']>
|
|
557
|
+
>
|
|
558
|
+
),
|
|
559
559
|
) => any | Promise<any>
|
|
560
560
|
|
|
561
561
|
export type Isolate<T> = {
|
|
562
|
-
|
|
562
|
+
[P in keyof T]: T[P]
|
|
563
563
|
}
|
|
564
564
|
|
|
565
565
|
export type DocumentDecoration = Partial<OpenAPIV3.OperationObject> & {
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
566
|
+
/**
|
|
567
|
+
* Pass `true` to hide route from OpenAPI/swagger document
|
|
568
|
+
* */
|
|
569
|
+
hide?: boolean
|
|
570
570
|
}
|
|
571
571
|
|
|
572
572
|
export type LocalHook<
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
573
|
+
LocalSchema extends InputSchema,
|
|
574
|
+
Schema extends RouteSchema,
|
|
575
|
+
Singleton extends SingletonBase,
|
|
576
|
+
Errors extends Record<string, Error>,
|
|
577
|
+
Extension extends BaseMacro,
|
|
578
|
+
Path extends string = '',
|
|
579
|
+
TypedRoute extends RouteSchema = Schema extends {
|
|
580
|
+
params: Record<string, unknown>
|
|
581
|
+
}
|
|
582
|
+
? Schema
|
|
583
|
+
: Schema & {
|
|
584
|
+
params: undefined extends Schema['params']
|
|
585
|
+
? ResolvePath<Path>
|
|
586
|
+
: Schema['params']
|
|
587
|
+
},
|
|
588
588
|
> = (LocalSchema extends {} ? LocalSchema : Isolate<LocalSchema>) &
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
589
|
+
Extension & {
|
|
590
|
+
detail?: DocumentDecoration
|
|
591
|
+
/**
|
|
592
|
+
* Short for 'Content-Type'
|
|
593
|
+
*
|
|
594
|
+
* Available:
|
|
595
|
+
* - 'none': do not parse body
|
|
596
|
+
* - 'text' / 'text/plain': parse body as string
|
|
597
|
+
* - 'json' / 'application/json': parse body as json
|
|
598
|
+
* - 'formdata' / 'multipart/form-data': parse body as form-data
|
|
599
|
+
* - 'urlencoded' / 'application/x-www-form-urlencoded: parse body as urlencoded
|
|
600
|
+
* - 'arraybuffer': parse body as readable stream
|
|
601
|
+
*/
|
|
602
|
+
type?: ContentType
|
|
603
|
+
}
|
|
604
604
|
|
|
605
605
|
export type ComposedHandler = (context: Context) => MaybePromise<Response>
|
|
606
606
|
|
|
607
607
|
export interface InternalRoute {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
608
|
+
method: HTTPMethod
|
|
609
|
+
path: string
|
|
610
|
+
composed: ComposedHandler | Response | null
|
|
611
|
+
handler: Handler
|
|
612
|
+
hooks: LocalHook<any, any, any, any, any, any, any>
|
|
613
613
|
}
|
|
614
614
|
|
|
615
615
|
export type ListenCallback = (server: Server) => MaybePromise<void>
|
|
616
616
|
|
|
617
617
|
export type AddPrefix<Prefix extends string, T> = {
|
|
618
|
-
|
|
618
|
+
[K in keyof T as Prefix extends string ? `${Prefix}${K & string}` : K]: T[K]
|
|
619
619
|
}
|
|
620
620
|
|
|
621
621
|
export type AddPrefixCapitalize<Prefix extends string, T> = {
|
|
622
|
-
|
|
622
|
+
[K in keyof T as `${Prefix}${Capitalize<K & string>}`]: T[K]
|
|
623
623
|
}
|
|
624
624
|
|
|
625
625
|
export type AddSuffix<Suffix extends string, T> = {
|
|
626
|
-
|
|
626
|
+
[K in keyof T as `${K & string}${Suffix}`]: T[K]
|
|
627
627
|
}
|
|
628
628
|
|
|
629
629
|
export type AddSuffixCapitalize<Suffix extends string, T> = {
|
|
630
|
-
|
|
630
|
+
[K in keyof T as `${K & string}${Capitalize<Suffix>}`]: T[K]
|
|
631
631
|
}
|
|
632
632
|
|
|
633
633
|
export type BaseMacro = Record<
|
|
634
|
-
|
|
635
|
-
|
|
634
|
+
string,
|
|
635
|
+
string | number | boolean | Object | undefined | null
|
|
636
636
|
>
|
|
637
637
|
export type BaseMacroFn = Record<string, (...a: any) => unknown>
|
|
638
638
|
|
|
639
639
|
type _CreateEden<
|
|
640
|
-
|
|
641
|
-
|
|
640
|
+
Path extends string,
|
|
641
|
+
Property extends Record<string, unknown> = {},
|
|
642
642
|
> = Path extends `${infer Start}/${infer Rest}`
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
643
|
+
? {
|
|
644
|
+
[x in Start]: _CreateEden<Rest, Property>
|
|
645
|
+
}
|
|
646
|
+
: {
|
|
647
|
+
[x in Path]: Property
|
|
648
|
+
}
|
|
649
649
|
|
|
650
650
|
export type CreateEden<
|
|
651
|
-
|
|
652
|
-
|
|
651
|
+
Path extends string,
|
|
652
|
+
Property extends Record<string, unknown> = {},
|
|
653
653
|
> = Path extends `/${infer Rest}`
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
654
|
+
? _CreateEden<Rest, Property>
|
|
655
|
+
: Path extends ''
|
|
656
|
+
? _CreateEden<'index', Property>
|
|
657
|
+
: _CreateEden<Path, Property>
|
|
658
658
|
|
|
659
659
|
export type ComposeSpiceflowResponse<Response, Handle> = Handle extends (
|
|
660
|
-
|
|
660
|
+
...a: any[]
|
|
661
661
|
) => infer A
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
Response,
|
|
665
|
-
Replace<Awaited<Handle>, BunFile, File>
|
|
666
|
-
>
|
|
662
|
+
? _ComposeSpiceflowResponse<Response, Awaited<A>>
|
|
663
|
+
: _ComposeSpiceflowResponse<Response, Replace<Awaited<Handle>, BunFile, File>>
|
|
667
664
|
|
|
668
665
|
type _ComposeSpiceflowResponse<Response, Handle> = Prettify<
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
666
|
+
{} extends Response
|
|
667
|
+
? {
|
|
668
|
+
200: Exclude<Handle, { [ELYSIA_RESPONSE]: any }>
|
|
669
|
+
} & {
|
|
670
|
+
[ErrorResponse in Extract<
|
|
671
|
+
Handle,
|
|
672
|
+
{ response: any }
|
|
673
|
+
> as ErrorResponse extends {
|
|
674
|
+
[ELYSIA_RESPONSE]: infer Status extends number
|
|
675
|
+
}
|
|
676
|
+
? Status
|
|
677
|
+
: never]: ErrorResponse['response']
|
|
678
|
+
}
|
|
679
|
+
: Response
|
|
683
680
|
>
|
|
684
681
|
|
|
685
682
|
export type MergeSpiceflowInstances<
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
683
|
+
Instances extends Spiceflow<any, any, any, any, any, any>[] = [],
|
|
684
|
+
Prefix extends string = '',
|
|
685
|
+
Scoped extends boolean = false,
|
|
686
|
+
Singleton extends SingletonBase = {
|
|
687
|
+
state: {}
|
|
688
|
+
},
|
|
689
|
+
Definitions extends DefinitionBase = {
|
|
690
|
+
type: {}
|
|
691
|
+
error: {}
|
|
692
|
+
},
|
|
693
|
+
Metadata extends MetadataBase = {
|
|
694
|
+
schema: {}
|
|
695
|
+
macro: {}
|
|
696
|
+
macroFn: {}
|
|
697
|
+
},
|
|
698
|
+
Routes extends RouteBase = {},
|
|
702
699
|
> = Instances extends [
|
|
703
|
-
|
|
704
|
-
|
|
700
|
+
infer Current extends Spiceflow<any, any, any, any, any, any>,
|
|
701
|
+
...infer Rest extends Spiceflow<any, any, any, any, any, any>[],
|
|
705
702
|
]
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
703
|
+
? Current['_types']['Scoped'] extends true
|
|
704
|
+
? MergeSpiceflowInstances<
|
|
705
|
+
Rest,
|
|
706
|
+
Prefix,
|
|
707
|
+
Scoped,
|
|
708
|
+
Singleton,
|
|
709
|
+
Definitions,
|
|
710
|
+
Metadata,
|
|
711
|
+
Routes
|
|
712
|
+
>
|
|
713
|
+
: MergeSpiceflowInstances<
|
|
714
|
+
Rest,
|
|
715
|
+
Prefix,
|
|
716
|
+
Scoped,
|
|
717
|
+
Singleton & Current['_types']['Singleton'],
|
|
718
|
+
Definitions & Current['_types']['Definitions'],
|
|
719
|
+
Metadata & Current['_types']['Metadata'],
|
|
720
|
+
Routes &
|
|
721
|
+
(Prefix extends ``
|
|
722
|
+
? Current['_routes']
|
|
723
|
+
: AddPrefix<Prefix, Current['_routes']>)
|
|
724
|
+
>
|
|
725
|
+
: Spiceflow<
|
|
726
|
+
Prefix,
|
|
727
|
+
Scoped,
|
|
728
|
+
{
|
|
729
|
+
state: Prettify<Singleton['state']>
|
|
730
|
+
},
|
|
731
|
+
{
|
|
732
|
+
type: Prettify<Definitions['type']>
|
|
733
|
+
error: Prettify<Definitions['error']>
|
|
734
|
+
},
|
|
735
|
+
{
|
|
736
|
+
schema: Prettify<Metadata['schema']>
|
|
737
|
+
macro: Prettify<Metadata['macro']>
|
|
738
|
+
macroFn: Prettify<Metadata['macroFn']>
|
|
739
|
+
},
|
|
740
|
+
Routes
|
|
741
|
+
>
|
|
745
742
|
|
|
746
743
|
export type LifeCycleType = 'global' | 'local' | 'scoped'
|
|
747
744
|
|
|
748
745
|
export type UnionToIntersect<U> = (
|
|
749
|
-
|
|
746
|
+
U extends unknown ? (arg: U) => 0 : never
|
|
750
747
|
) extends (arg: infer I) => 0
|
|
751
|
-
|
|
752
|
-
|
|
748
|
+
? I
|
|
749
|
+
: never
|
|
753
750
|
|
|
754
751
|
export type ContextAppendType = 'append' | 'override'
|
|
755
752
|
|
|
756
753
|
export type HTTPHeaders = Record<string, string> & {
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
754
|
+
// Authentication
|
|
755
|
+
'www-authenticate'?: string
|
|
756
|
+
authorization?: string
|
|
757
|
+
'proxy-authenticate'?: string
|
|
758
|
+
'proxy-authorization'?: string
|
|
759
|
+
|
|
760
|
+
// Caching
|
|
761
|
+
age?: string
|
|
762
|
+
'cache-control'?: string
|
|
763
|
+
'clear-site-data'?: string
|
|
764
|
+
expires?: string
|
|
765
|
+
'no-vary-search'?: string
|
|
766
|
+
pragma?: string
|
|
767
|
+
|
|
768
|
+
// Conditionals
|
|
769
|
+
'last-modified'?: string
|
|
770
|
+
etag?: string
|
|
771
|
+
'if-match'?: string
|
|
772
|
+
'if-none-match'?: string
|
|
773
|
+
'if-modified-since'?: string
|
|
774
|
+
'if-unmodified-since'?: string
|
|
775
|
+
vary?: string
|
|
776
|
+
|
|
777
|
+
// Connection management
|
|
778
|
+
connection?: string
|
|
779
|
+
'keep-alive'?: string
|
|
780
|
+
|
|
781
|
+
// Content negotiation
|
|
782
|
+
accept?: string
|
|
783
|
+
'accept-encoding'?: string
|
|
784
|
+
'accept-language'?: string
|
|
785
|
+
|
|
786
|
+
// Controls
|
|
787
|
+
expect?: string
|
|
788
|
+
'max-forwards'?: string
|
|
789
|
+
|
|
790
|
+
// Cokies
|
|
791
|
+
cookie?: string
|
|
792
|
+
'set-cookie'?: string | string[]
|
|
793
|
+
|
|
794
|
+
// CORS
|
|
795
|
+
'access-control-allow-origin'?: string
|
|
796
|
+
'access-control-allow-credentials'?: string
|
|
797
|
+
'access-control-allow-headers'?: string
|
|
798
|
+
'access-control-allow-methods'?: string
|
|
799
|
+
'access-control-expose-headers'?: string
|
|
800
|
+
'access-control-max-age'?: string
|
|
801
|
+
'access-control-request-headers'?: string
|
|
802
|
+
'access-control-request-method'?: string
|
|
803
|
+
origin?: string
|
|
804
|
+
'timing-allow-origin'?: string
|
|
805
|
+
|
|
806
|
+
// Downloads
|
|
807
|
+
'content-disposition'?: string
|
|
808
|
+
|
|
809
|
+
// Message body information
|
|
810
|
+
'content-length'?: string
|
|
811
|
+
'content-type'?: string
|
|
812
|
+
'content-encoding'?: string
|
|
813
|
+
'content-language'?: string
|
|
814
|
+
'content-location'?: string
|
|
815
|
+
|
|
816
|
+
// Proxies
|
|
817
|
+
forwarded?: string
|
|
818
|
+
via?: string
|
|
819
|
+
|
|
820
|
+
// Redirects
|
|
821
|
+
location?: string
|
|
822
|
+
refresh?: string
|
|
823
|
+
|
|
824
|
+
// Request context
|
|
825
|
+
// from?: string
|
|
826
|
+
// host?: string
|
|
827
|
+
// referer?: string
|
|
828
|
+
// 'user-agent'?: string
|
|
829
|
+
|
|
830
|
+
// Response context
|
|
831
|
+
allow?: string
|
|
832
|
+
server?: 'spiceflow' | (string & {})
|
|
833
|
+
|
|
834
|
+
// Range requests
|
|
835
|
+
'accept-ranges'?: string
|
|
836
|
+
range?: string
|
|
837
|
+
'if-range'?: string
|
|
838
|
+
'content-range'?: string
|
|
839
|
+
|
|
840
|
+
// Security
|
|
841
|
+
'content-security-policy'?: string
|
|
842
|
+
'content-security-policy-report-only'?: string
|
|
843
|
+
'cross-origin-embedder-policy'?: string
|
|
844
|
+
'cross-origin-opener-policy'?: string
|
|
845
|
+
'cross-origin-resource-policy'?: string
|
|
846
|
+
'expect-ct'?: string
|
|
847
|
+
'permission-policy'?: string
|
|
848
|
+
'strict-transport-security'?: string
|
|
849
|
+
'upgrade-insecure-requests'?: string
|
|
850
|
+
'x-content-type-options'?: string
|
|
851
|
+
'x-frame-options'?: string
|
|
852
|
+
'x-xss-protection'?: string
|
|
853
|
+
|
|
854
|
+
// Server-sent events
|
|
855
|
+
'last-event-id'?: string
|
|
856
|
+
'ping-from'?: string
|
|
857
|
+
'ping-to'?: string
|
|
858
|
+
'report-to'?: string
|
|
859
|
+
|
|
860
|
+
// Transfer coding
|
|
861
|
+
te?: string
|
|
862
|
+
trailer?: string
|
|
863
|
+
'transfer-encoding'?: string
|
|
864
|
+
|
|
865
|
+
// Other
|
|
866
|
+
'alt-svg'?: string
|
|
867
|
+
'alt-used'?: string
|
|
868
|
+
date?: string
|
|
869
|
+
dnt?: string
|
|
870
|
+
'early-data'?: string
|
|
871
|
+
'large-allocation'?: string
|
|
872
|
+
link?: string
|
|
873
|
+
'retry-after'?: string
|
|
874
|
+
'service-worker-allowed'?: string
|
|
875
|
+
'source-map'?: string
|
|
876
|
+
upgrade?: string
|
|
877
|
+
|
|
878
|
+
// Non-standard
|
|
879
|
+
'x-dns-prefetch-control'?: string
|
|
880
|
+
'x-forwarded-for'?: string
|
|
881
|
+
'x-forwarded-host'?: string
|
|
882
|
+
'x-forwarded-proto'?: string
|
|
883
|
+
'x-powered-by'?: 'spiceflow' | (string & {})
|
|
884
|
+
'x-request-id'?: string
|
|
885
|
+
'x-requested-with'?: string
|
|
886
|
+
'x-robots-tag'?: string
|
|
887
|
+
'x-ua-compatible'?: string
|
|
891
888
|
}
|
|
892
889
|
|
|
893
890
|
export type JoinPath<A extends string, B extends string> = `${A}${B extends '/'
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
891
|
+
? '/index'
|
|
892
|
+
: B extends ''
|
|
893
|
+
? B
|
|
894
|
+
: B extends `/${string}`
|
|
895
|
+
? B
|
|
896
|
+
: B}`
|
|
900
897
|
|
|
901
898
|
export type PartialWithRequired<T, K extends keyof T> = Partial<Omit<T, K>> &
|
|
902
|
-
|
|
899
|
+
Pick<T, K>
|