spiceflow 1.0.0 → 1.0.2
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 +147 -0
- package/dist/client/index.d.ts +4 -3
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +5 -5
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +4 -5
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/ws.d.ts +4 -4
- package/dist/client/ws.d.ts.map +1 -1
- package/dist/client/ws.js.map +1 -1
- package/dist/client.test.js +9 -8
- package/dist/client.test.js.map +1 -1
- package/dist/elysia-fork/error.d.ts +5 -65
- package/dist/elysia-fork/error.d.ts.map +1 -1
- package/dist/elysia-fork/error.js +2 -2
- package/dist/elysia-fork/error.js.map +1 -1
- package/dist/elysia-fork/types.d.ts +27 -116
- package/dist/elysia-fork/types.d.ts.map +1 -1
- package/dist/elysia-fork/types.js +1 -2
- package/dist/elysia-fork/types.js.map +1 -1
- package/dist/elysia-fork/utils.d.ts +1 -62
- package/dist/elysia-fork/utils.d.ts.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/openapi.d.ts +68 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +250 -0
- package/dist/openapi.js.map +1 -0
- package/dist/spiceflow.d.ts +48 -52
- package/dist/spiceflow.d.ts.map +1 -1
- package/dist/spiceflow.js +148 -87
- package/dist/spiceflow.js.map +1 -1
- package/dist/spiceflow.test.js +80 -43
- package/dist/spiceflow.test.js.map +1 -1
- package/dist/stream.test.js +14 -14
- package/dist/stream.test.js.map +1 -1
- package/dist/zod.test.d.ts +2 -0
- package/dist/zod.test.d.ts.map +1 -0
- package/dist/zod.test.js +59 -0
- package/dist/zod.test.js.map +1 -0
- package/package.json +7 -4
- package/src/client/index.ts +10 -8
- package/src/client/types.ts +4 -4
- package/src/client/ws.ts +4 -4
- package/src/client.test.ts +9 -8
- package/src/elysia-fork/context.ts +2 -2
- package/src/elysia-fork/error.ts +3 -3
- package/src/elysia-fork/types.ts +108 -284
- package/src/index.ts +2 -0
- package/src/openapi.ts +426 -0
- package/src/spiceflow.test.ts +117 -64
- package/src/spiceflow.ts +261 -179
- package/src/stream.test.ts +14 -14
- package/src/zod.test.ts +71 -0
package/src/elysia-fork/types.ts
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
// https://github.com/remorses/elysia/blob/main/src/types.ts#L6
|
|
2
|
+
import z from 'zod'
|
|
2
3
|
|
|
3
4
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
4
5
|
|
|
5
|
-
import type { BunFile, Serve, Server, WebSocketHandler } from 'bun'
|
|
6
|
-
|
|
7
|
-
|
|
8
6
|
import type {
|
|
9
|
-
|
|
10
|
-
TObject,
|
|
7
|
+
OptionalKind,
|
|
11
8
|
Static,
|
|
12
|
-
TAnySchema,
|
|
13
|
-
TNull,
|
|
14
|
-
TUndefined,
|
|
15
9
|
StaticDecode,
|
|
16
|
-
|
|
10
|
+
TAnySchema,
|
|
11
|
+
TSchema,
|
|
17
12
|
} from '@sinclair/typebox'
|
|
18
13
|
import type { TypeCheck, ValueError } from '@sinclair/typebox/compiler'
|
|
14
|
+
import type { BunFile, Server } from 'bun'
|
|
19
15
|
|
|
20
16
|
import type { OpenAPIV3 } from 'openapi-types'
|
|
21
17
|
|
|
18
|
+
import { Spiceflow } from '../spiceflow'
|
|
22
19
|
import type { Context, ErrorContext, PreContext } from './context'
|
|
23
20
|
import {
|
|
24
21
|
ELYSIA_RESPONSE,
|
|
@@ -26,111 +23,9 @@ import {
|
|
|
26
23
|
InvalidCookieSignature,
|
|
27
24
|
NotFoundError,
|
|
28
25
|
ParseError,
|
|
29
|
-
ValidationError
|
|
26
|
+
ValidationError,
|
|
30
27
|
} from './error'
|
|
31
|
-
import {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export type ElysiaConfig<
|
|
35
|
-
Prefix extends string | undefined,
|
|
36
|
-
Scoped extends boolean | undefined
|
|
37
|
-
> = {
|
|
38
|
-
/**
|
|
39
|
-
* Path prefix of the instance
|
|
40
|
-
*
|
|
41
|
-
* @default '''
|
|
42
|
-
*/
|
|
43
|
-
prefix?: Prefix
|
|
44
|
-
/**
|
|
45
|
-
* If set to true, other Elysia handler will not inherits global life-cycle, store, decorators from the current instance
|
|
46
|
-
*
|
|
47
|
-
* @default false
|
|
48
|
-
*/
|
|
49
|
-
scoped?: Scoped
|
|
50
|
-
/**
|
|
51
|
-
* Name of the instance for debugging, and plugin deduplication purpose
|
|
52
|
-
*/
|
|
53
|
-
name?: string
|
|
54
|
-
/**
|
|
55
|
-
* Seed for generating checksum for plugin deduplication
|
|
56
|
-
*
|
|
57
|
-
* @see https://elysiajs.com/essential/plugin.html#plugin-deduplication
|
|
58
|
-
*/
|
|
59
|
-
seed?: unknown
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* OpenAPI documentation (use in Swagger)
|
|
63
|
-
*
|
|
64
|
-
* @see https://swagger.io/specification/
|
|
65
|
-
*/
|
|
66
|
-
detail?: DocumentDecoration
|
|
67
|
-
/**
|
|
68
|
-
* OpenAPI tags
|
|
69
|
-
*
|
|
70
|
-
* current instance' routes with tags
|
|
71
|
-
*
|
|
72
|
-
* @see https://swagger.io/specification/#tag-object
|
|
73
|
-
*/
|
|
74
|
-
tags?: DocumentDecoration['tags']
|
|
75
|
-
/**
|
|
76
|
-
* Warm up Elysia before starting the server
|
|
77
|
-
*
|
|
78
|
-
* This will perform Ahead of Time compilation and generate code for route handlers
|
|
79
|
-
*
|
|
80
|
-
* If set to false, Elysia will perform Just in Time compilation
|
|
81
|
-
*
|
|
82
|
-
* Only required for root instance (instance which use listen) to effect
|
|
83
|
-
*
|
|
84
|
-
* ! If performing a benchmark, it's recommended to set this to `true`
|
|
85
|
-
*
|
|
86
|
-
* @default false
|
|
87
|
-
*/
|
|
88
|
-
precompile?:
|
|
89
|
-
| boolean
|
|
90
|
-
| {
|
|
91
|
-
/**
|
|
92
|
-
* Perform dynamic code generation for route handlers before starting the server
|
|
93
|
-
*
|
|
94
|
-
* @default false
|
|
95
|
-
*/
|
|
96
|
-
compose?: boolean
|
|
97
|
-
/**
|
|
98
|
-
* Perform Ahead of Time compilation for schema before starting the server
|
|
99
|
-
*
|
|
100
|
-
* @default false
|
|
101
|
-
*/
|
|
102
|
-
schema?: boolean
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// /**
|
|
106
|
-
// * Override websocket configuration
|
|
107
|
-
// *
|
|
108
|
-
// * @see https://bun.sh/docs/api/websockets
|
|
109
|
-
// */
|
|
110
|
-
// websocket?: Omit<
|
|
111
|
-
// WebSocketHandler<any>,
|
|
112
|
-
// 'open' | 'close' | 'message' | 'drain'
|
|
113
|
-
// >
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Capture more detail information for each dependencies
|
|
117
|
-
*/
|
|
118
|
-
analytic?: boolean
|
|
119
|
-
/**
|
|
120
|
-
* Enable experimental features
|
|
121
|
-
*/
|
|
122
|
-
experimental?: {}
|
|
123
|
-
/**
|
|
124
|
-
* If enabled, the handlers will run a [clean](https://github.com/sinclairzx81/typebox?tab=readme-ov-file#clean) on incoming and outgoing bodies instead of failing directly.
|
|
125
|
-
* This allows for sending unknown or disallowed properties in the bodies. These will simply be filtered out instead of failing the request.
|
|
126
|
-
* This has no effect when the schemas allow additional properties.
|
|
127
|
-
* Since this uses dynamic schema it may have an impact on performance.
|
|
128
|
-
*
|
|
129
|
-
* @default false
|
|
130
|
-
*/
|
|
131
|
-
normalize?: boolean
|
|
132
|
-
}
|
|
133
|
-
|
|
28
|
+
import { ZodTypeAny } from 'zod'
|
|
134
29
|
|
|
135
30
|
export type MaybeArray<T> = T | T[]
|
|
136
31
|
export type MaybePromise<T> = T | Promise<T>
|
|
@@ -195,7 +90,7 @@ export type Reconcile<
|
|
|
195
90
|
B extends Object,
|
|
196
91
|
Override extends boolean = false,
|
|
197
92
|
// Detect Stack limit, eg. circular dependency
|
|
198
|
-
Stack extends number[] = []
|
|
93
|
+
Stack extends number[] = [],
|
|
199
94
|
> = Stack['length'] extends 16
|
|
200
95
|
? A
|
|
201
96
|
: Override extends true
|
|
@@ -290,11 +185,15 @@ type OptionalField = {
|
|
|
290
185
|
[OptionalKind]: 'Optional'
|
|
291
186
|
}
|
|
292
187
|
|
|
188
|
+
export type TypeSchema = TSchema | ZodTypeAny
|
|
189
|
+
|
|
293
190
|
export type UnwrapSchema<
|
|
294
|
-
Schema extends
|
|
295
|
-
Definitions extends Record<string, unknown> = {}
|
|
191
|
+
Schema extends TypeSchema | string | undefined,
|
|
192
|
+
Definitions extends Record<string, unknown> = {},
|
|
296
193
|
> = undefined extends Schema
|
|
297
194
|
? unknown
|
|
195
|
+
: Schema extends ZodTypeAny
|
|
196
|
+
? z.infer<Schema>
|
|
298
197
|
: Schema extends TSchema
|
|
299
198
|
? Schema extends OptionalField
|
|
300
199
|
? Prettify<Partial<Static<Schema>>>
|
|
@@ -305,31 +204,16 @@ export type UnwrapSchema<
|
|
|
305
204
|
: Definitions
|
|
306
205
|
: unknown
|
|
307
206
|
|
|
308
|
-
export type UnwrapBodySchema<
|
|
309
|
-
Schema extends TSchema | string | undefined,
|
|
310
|
-
Definitions extends Record<string, unknown> = {}
|
|
311
|
-
> = undefined extends Schema
|
|
312
|
-
? unknown
|
|
313
|
-
: Schema extends TSchema
|
|
314
|
-
? Schema extends OptionalField
|
|
315
|
-
? Prettify<Partial<Static<Schema>>> | null
|
|
316
|
-
: StaticDecode<Schema>
|
|
317
|
-
: Schema extends string
|
|
318
|
-
? Definitions extends Record<Schema, infer NamedSchema>
|
|
319
|
-
? NamedSchema
|
|
320
|
-
: Definitions
|
|
321
|
-
: unknown
|
|
322
|
-
|
|
323
207
|
export interface UnwrapRoute<
|
|
324
208
|
in out Schema extends InputSchema<any>,
|
|
325
|
-
in out Definitions extends DefinitionBase['type'] = {}
|
|
209
|
+
in out Definitions extends DefinitionBase['type'] = {},
|
|
326
210
|
> {
|
|
327
|
-
body:
|
|
211
|
+
body: UnwrapSchema<Schema['body'], Definitions>
|
|
328
212
|
// headers: UnwrapSchema<Schema['headers'], Definitions>
|
|
329
213
|
// query: UnwrapSchema<Schema['query'], Definitions>
|
|
330
214
|
// params: UnwrapSchema<Schema['params'], Definitions>
|
|
331
215
|
// cookie: UnwrapSchema<Schema['cookie'], Definitions>
|
|
332
|
-
response: Schema['response'] extends
|
|
216
|
+
response: Schema['response'] extends TypeSchema | string
|
|
333
217
|
? {
|
|
334
218
|
200: CoExist<
|
|
335
219
|
UnwrapSchema<Schema['response'], Definitions>,
|
|
@@ -337,7 +221,7 @@ export interface UnwrapRoute<
|
|
|
337
221
|
BunFile
|
|
338
222
|
>
|
|
339
223
|
}
|
|
340
|
-
: Schema['response'] extends Record<number,
|
|
224
|
+
: Schema['response'] extends Record<number, TypeSchema | string>
|
|
341
225
|
? {
|
|
342
226
|
[k in keyof Schema['response']]: CoExist<
|
|
343
227
|
UnwrapSchema<Schema['response'][k], Definitions>,
|
|
@@ -348,50 +232,6 @@ export interface UnwrapRoute<
|
|
|
348
232
|
: unknown | void
|
|
349
233
|
}
|
|
350
234
|
|
|
351
|
-
// export interface UnwrapGroupGuardRoute<
|
|
352
|
-
// in out Schema extends InputSchema<any>,
|
|
353
|
-
// in out Definitions extends Record<string, unknown> = {},
|
|
354
|
-
// Path extends string = ''
|
|
355
|
-
// > {
|
|
356
|
-
// body: UnwrapBodySchema<Schema['body'], Definitions>
|
|
357
|
-
// headers: UnwrapSchema<
|
|
358
|
-
// Schema['headers'],
|
|
359
|
-
// Definitions
|
|
360
|
-
// > extends infer A extends Record<string, unknown>
|
|
361
|
-
// ? A
|
|
362
|
-
// : undefined
|
|
363
|
-
// query: UnwrapSchema<
|
|
364
|
-
// Schema['query'],
|
|
365
|
-
// Definitions
|
|
366
|
-
// > extends infer A extends Record<string, unknown>
|
|
367
|
-
// ? A
|
|
368
|
-
// : undefined
|
|
369
|
-
// params: UnwrapSchema<
|
|
370
|
-
// Schema['params'],
|
|
371
|
-
// Definitions
|
|
372
|
-
// > extends infer A extends Record<string, unknown>
|
|
373
|
-
// ? A
|
|
374
|
-
// : Path extends `${string}/${':' | '*'}${string}`
|
|
375
|
-
// ? Record<GetPathParameter<Path>, string>
|
|
376
|
-
// : never
|
|
377
|
-
// cookie: UnwrapSchema<
|
|
378
|
-
// Schema['cookie'],
|
|
379
|
-
// Definitions
|
|
380
|
-
// > extends infer A extends Record<string, unknown>
|
|
381
|
-
// ? A
|
|
382
|
-
// : undefined
|
|
383
|
-
// response: Schema['response'] extends TSchema | string
|
|
384
|
-
// ? UnwrapSchema<Schema['response'], Definitions>
|
|
385
|
-
// : Schema['response'] extends {
|
|
386
|
-
// [k in string]: TSchema | string
|
|
387
|
-
// }
|
|
388
|
-
// ? UnwrapSchema<
|
|
389
|
-
// Schema['response'][keyof Schema['response']],
|
|
390
|
-
// Definitions
|
|
391
|
-
// >
|
|
392
|
-
// : unknown | void
|
|
393
|
-
// }
|
|
394
|
-
|
|
395
235
|
export type HookContainer<T extends Function = Function> = {
|
|
396
236
|
checksum?: number
|
|
397
237
|
scope?: LifeCycleType
|
|
@@ -478,21 +318,21 @@ export type HTTPMethod =
|
|
|
478
318
|
| 'ALL'
|
|
479
319
|
|
|
480
320
|
export interface InputSchema<Name extends string = string> {
|
|
481
|
-
body?:
|
|
321
|
+
body?: TypeSchema | Name
|
|
482
322
|
// headers?: TObject | TNull | TUndefined | Name
|
|
483
323
|
// query?: TObject | TNull | TUndefined | Name
|
|
484
324
|
// params?: TObject | TNull | TUndefined | Name
|
|
485
325
|
// cookie?: TObject | TNull | TUndefined | Name
|
|
486
326
|
response?:
|
|
487
|
-
|
|
|
488
|
-
| Record<number,
|
|
327
|
+
| TypeSchema
|
|
328
|
+
| Record<number, TypeSchema>
|
|
489
329
|
| Name
|
|
490
|
-
| Record<number, Name |
|
|
330
|
+
| Record<number, Name | TypeSchema>
|
|
491
331
|
}
|
|
492
332
|
|
|
493
333
|
export interface MergeSchema<
|
|
494
334
|
in out A extends RouteSchema,
|
|
495
|
-
in out B extends RouteSchema
|
|
335
|
+
in out B extends RouteSchema,
|
|
496
336
|
> {
|
|
497
337
|
body: undefined extends A['body'] ? B['body'] : A['body']
|
|
498
338
|
headers: undefined extends A['headers'] ? B['headers'] : A['headers']
|
|
@@ -516,9 +356,9 @@ export type Handler<
|
|
|
516
356
|
derive: {}
|
|
517
357
|
resolve: {}
|
|
518
358
|
},
|
|
519
|
-
Path extends string = ''
|
|
359
|
+
Path extends string = '',
|
|
520
360
|
> = (
|
|
521
|
-
context: Context<Route, Singleton, Path
|
|
361
|
+
context: Context<Route, Singleton, Path>,
|
|
522
362
|
) => MaybePromise<
|
|
523
363
|
{} extends Route['response']
|
|
524
364
|
? unknown
|
|
@@ -560,48 +400,31 @@ export type InlineHandler<
|
|
|
560
400
|
resolve: {}
|
|
561
401
|
},
|
|
562
402
|
Path extends string = '',
|
|
563
|
-
MacroContext = {}
|
|
564
|
-
> =
|
|
565
|
-
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
[ELYSIA_RESPONSE]: Status
|
|
589
|
-
}
|
|
590
|
-
}[keyof Route['response']]
|
|
591
|
-
>)
|
|
592
|
-
| ({} extends Route['response']
|
|
593
|
-
? string | number | boolean | Object
|
|
594
|
-
:
|
|
595
|
-
| (Route['response'] extends { 200: any }
|
|
596
|
-
? Route['response']
|
|
597
|
-
: string | number | boolean | Object)
|
|
598
|
-
| Route['response'][keyof Route['response']]
|
|
599
|
-
| {
|
|
600
|
-
[Status in keyof Route['response']]: {
|
|
601
|
-
_type: Record<Status, Route['response'][Status]>
|
|
602
|
-
[ELYSIA_RESPONSE]: Status
|
|
603
|
-
}
|
|
604
|
-
}[keyof Route['response']])
|
|
403
|
+
MacroContext = {},
|
|
404
|
+
> = (
|
|
405
|
+
context: MacroContext extends Record<string | number | symbol, unknown>
|
|
406
|
+
? Prettify<MacroContext & Context<Route, Singleton, Path>>
|
|
407
|
+
: Context<Route, Singleton, Path>,
|
|
408
|
+
) =>
|
|
409
|
+
| Response
|
|
410
|
+
| MaybePromise<
|
|
411
|
+
{} extends Route['response']
|
|
412
|
+
? unknown
|
|
413
|
+
:
|
|
414
|
+
| (Route['response'] extends { 200: any }
|
|
415
|
+
? Route['response']
|
|
416
|
+
: string | number | boolean | Object)
|
|
417
|
+
| Route['response'][keyof Route['response']]
|
|
418
|
+
| {
|
|
419
|
+
[Status in keyof Route['response']]: {
|
|
420
|
+
_type: Record<
|
|
421
|
+
Status,
|
|
422
|
+
Route['response'][Status]
|
|
423
|
+
>
|
|
424
|
+
[ELYSIA_RESPONSE]: Status
|
|
425
|
+
}
|
|
426
|
+
}[keyof Route['response']]
|
|
427
|
+
>
|
|
605
428
|
|
|
606
429
|
export type OptionalHandler<
|
|
607
430
|
in out Route extends RouteSchema = {},
|
|
@@ -611,9 +434,9 @@ export type OptionalHandler<
|
|
|
611
434
|
derive: {}
|
|
612
435
|
resolve: {}
|
|
613
436
|
},
|
|
614
|
-
Path extends string = ''
|
|
437
|
+
Path extends string = '',
|
|
615
438
|
> = Handler<Route, Singleton, Path> extends (
|
|
616
|
-
context: infer Context
|
|
439
|
+
context: infer Context,
|
|
617
440
|
) => infer Returned
|
|
618
441
|
? (context: Context) => Returned | MaybePromise<void>
|
|
619
442
|
: never
|
|
@@ -626,16 +449,16 @@ export type AfterHandler<
|
|
|
626
449
|
derive: {}
|
|
627
450
|
resolve: {}
|
|
628
451
|
},
|
|
629
|
-
Path extends string = ''
|
|
452
|
+
Path extends string = '',
|
|
630
453
|
> = Handler<Route, Singleton, Path> extends (
|
|
631
|
-
context: infer Context
|
|
454
|
+
context: infer Context,
|
|
632
455
|
) => infer Returned
|
|
633
456
|
? (
|
|
634
457
|
context: Prettify<
|
|
635
458
|
{
|
|
636
459
|
response: Route['response']
|
|
637
460
|
} & Context
|
|
638
|
-
|
|
461
|
+
>,
|
|
639
462
|
) => Returned | MaybePromise<void>
|
|
640
463
|
: never
|
|
641
464
|
|
|
@@ -647,7 +470,7 @@ export type MapResponse<
|
|
|
647
470
|
derive: {}
|
|
648
471
|
resolve: {}
|
|
649
472
|
},
|
|
650
|
-
Path extends string = ''
|
|
473
|
+
Path extends string = '',
|
|
651
474
|
> = Handler<
|
|
652
475
|
Omit<Route, 'response'> & {
|
|
653
476
|
response: MaybePromise<Response | undefined | unknown>
|
|
@@ -667,7 +490,7 @@ export type VoidHandler<
|
|
|
667
490
|
store: {}
|
|
668
491
|
derive: {}
|
|
669
492
|
resolve: {}
|
|
670
|
-
}
|
|
493
|
+
},
|
|
671
494
|
> = (context: Context<Route, Singleton>) => MaybePromise<void>
|
|
672
495
|
|
|
673
496
|
export type TransformHandler<
|
|
@@ -678,7 +501,7 @@ export type TransformHandler<
|
|
|
678
501
|
derive: {}
|
|
679
502
|
resolve: {}
|
|
680
503
|
},
|
|
681
|
-
BasePath extends string = ''
|
|
504
|
+
BasePath extends string = '',
|
|
682
505
|
> = {
|
|
683
506
|
(
|
|
684
507
|
context: Prettify<
|
|
@@ -689,7 +512,7 @@ export type TransformHandler<
|
|
|
689
512
|
},
|
|
690
513
|
BasePath
|
|
691
514
|
>
|
|
692
|
-
|
|
515
|
+
>,
|
|
693
516
|
): MaybePromise<void>
|
|
694
517
|
}
|
|
695
518
|
|
|
@@ -701,7 +524,7 @@ export type BodyHandler<
|
|
|
701
524
|
derive: {}
|
|
702
525
|
resolve: {}
|
|
703
526
|
},
|
|
704
|
-
Path extends string = ''
|
|
527
|
+
Path extends string = '',
|
|
705
528
|
> = (
|
|
706
529
|
context: Prettify<
|
|
707
530
|
{
|
|
@@ -715,14 +538,14 @@ export type BodyHandler<
|
|
|
715
538
|
*
|
|
716
539
|
* @example
|
|
717
540
|
* ```ts
|
|
718
|
-
* new
|
|
541
|
+
* new Spiceflow()
|
|
719
542
|
* .onParse(({ contentType, request }) => {
|
|
720
543
|
* if (contentType === 'application/json')
|
|
721
544
|
* return request.json()
|
|
722
545
|
* })
|
|
723
546
|
* ```
|
|
724
547
|
*/
|
|
725
|
-
contentType: string
|
|
548
|
+
contentType: string,
|
|
726
549
|
) => MaybePromise<any>
|
|
727
550
|
|
|
728
551
|
export type PreHandler<
|
|
@@ -732,7 +555,7 @@ export type PreHandler<
|
|
|
732
555
|
store: {}
|
|
733
556
|
derive: {}
|
|
734
557
|
resolve: {}
|
|
735
|
-
}
|
|
558
|
+
},
|
|
736
559
|
> = (context: PreContext<Singleton>) => MaybePromise<Route['response'] | void>
|
|
737
560
|
|
|
738
561
|
export type AfterResponseHandler<
|
|
@@ -742,17 +565,17 @@ export type AfterResponseHandler<
|
|
|
742
565
|
store: {}
|
|
743
566
|
derive: {}
|
|
744
567
|
resolve: {}
|
|
745
|
-
}
|
|
568
|
+
},
|
|
746
569
|
> = (
|
|
747
570
|
context: Prettify<
|
|
748
571
|
Context<Route, Singleton> & {
|
|
749
572
|
response: Route['response']
|
|
750
573
|
}
|
|
751
|
-
|
|
574
|
+
>,
|
|
752
575
|
) => MaybePromise<void>
|
|
753
576
|
|
|
754
577
|
export type GracefulHandler<
|
|
755
|
-
in Instance extends
|
|
578
|
+
in Instance extends Spiceflow<any, any, any, any, any, any, any, any>,
|
|
756
579
|
> = (data: Instance) => any
|
|
757
580
|
|
|
758
581
|
export type ErrorHandler<
|
|
@@ -775,7 +598,7 @@ export type ErrorHandler<
|
|
|
775
598
|
derive: {}
|
|
776
599
|
resolve: {}
|
|
777
600
|
schema: {}
|
|
778
|
-
}
|
|
601
|
+
},
|
|
779
602
|
> = (
|
|
780
603
|
context: ErrorContext<
|
|
781
604
|
Route,
|
|
@@ -898,7 +721,7 @@ export type ErrorHandler<
|
|
|
898
721
|
Volatile['resolve']
|
|
899
722
|
>
|
|
900
723
|
>
|
|
901
|
-
)
|
|
724
|
+
),
|
|
902
725
|
) => any | Promise<any>
|
|
903
726
|
|
|
904
727
|
export type Isolate<T> = {
|
|
@@ -927,7 +750,7 @@ export type LocalHook<
|
|
|
927
750
|
params: undefined extends Schema['params']
|
|
928
751
|
? ResolvePath<Path>
|
|
929
752
|
: Schema['params']
|
|
930
|
-
}
|
|
753
|
+
},
|
|
931
754
|
> = (LocalSchema extends {} ? LocalSchema : Isolate<LocalSchema>) &
|
|
932
755
|
Extension & {
|
|
933
756
|
/**
|
|
@@ -984,8 +807,6 @@ export interface InternalRoute {
|
|
|
984
807
|
hooks: LocalHook<any, any, any, any, any, any, any>
|
|
985
808
|
}
|
|
986
809
|
|
|
987
|
-
|
|
988
|
-
|
|
989
810
|
export type ListenCallback = (server: Server) => MaybePromise<void>
|
|
990
811
|
|
|
991
812
|
export type AddPrefix<Prefix extends string, T> = {
|
|
@@ -1052,54 +873,54 @@ export interface MacroManager<
|
|
|
1052
873
|
derive: {}
|
|
1053
874
|
resolve: {}
|
|
1054
875
|
},
|
|
1055
|
-
in out Errors extends Record<string, Error> = {}
|
|
876
|
+
in out Errors extends Record<string, Error> = {},
|
|
1056
877
|
> {
|
|
1057
878
|
onParse(fn: MaybeArray<BodyHandler<TypedRoute, Singleton>>): unknown
|
|
1058
879
|
onParse(
|
|
1059
880
|
options: MacroOptions,
|
|
1060
|
-
fn: MaybeArray<BodyHandler<TypedRoute, Singleton
|
|
881
|
+
fn: MaybeArray<BodyHandler<TypedRoute, Singleton>>,
|
|
1061
882
|
): unknown
|
|
1062
883
|
|
|
1063
884
|
onTransform(fn: MaybeArray<VoidHandler<TypedRoute, Singleton>>): unknown
|
|
1064
885
|
onTransform(
|
|
1065
886
|
options: MacroOptions,
|
|
1066
|
-
fn: MaybeArray<VoidHandler<TypedRoute, Singleton
|
|
887
|
+
fn: MaybeArray<VoidHandler<TypedRoute, Singleton>>,
|
|
1067
888
|
): unknown
|
|
1068
889
|
|
|
1069
890
|
onBeforeHandle(
|
|
1070
|
-
fn: MaybeArray<OptionalHandler<TypedRoute, Singleton
|
|
891
|
+
fn: MaybeArray<OptionalHandler<TypedRoute, Singleton>>,
|
|
1071
892
|
): unknown
|
|
1072
893
|
onBeforeHandle(
|
|
1073
894
|
options: MacroOptions,
|
|
1074
|
-
fn: MaybeArray<OptionalHandler<TypedRoute, Singleton
|
|
895
|
+
fn: MaybeArray<OptionalHandler<TypedRoute, Singleton>>,
|
|
1075
896
|
): unknown
|
|
1076
897
|
|
|
1077
898
|
onAfterHandle(fn: MaybeArray<AfterHandler<TypedRoute, Singleton>>): unknown
|
|
1078
899
|
onAfterHandle(
|
|
1079
900
|
options: MacroOptions,
|
|
1080
|
-
fn: MaybeArray<AfterHandler<TypedRoute, Singleton
|
|
901
|
+
fn: MaybeArray<AfterHandler<TypedRoute, Singleton>>,
|
|
1081
902
|
): unknown
|
|
1082
903
|
|
|
1083
904
|
onError(
|
|
1084
|
-
fn: MaybeArray<ErrorHandler<Errors, TypedRoute, Singleton
|
|
905
|
+
fn: MaybeArray<ErrorHandler<Errors, TypedRoute, Singleton>>,
|
|
1085
906
|
): unknown
|
|
1086
907
|
onError(
|
|
1087
908
|
options: MacroOptions,
|
|
1088
|
-
fn: MaybeArray<ErrorHandler<Errors, TypedRoute, Singleton
|
|
909
|
+
fn: MaybeArray<ErrorHandler<Errors, TypedRoute, Singleton>>,
|
|
1089
910
|
): unknown
|
|
1090
911
|
|
|
1091
912
|
mapResponse(fn: MaybeArray<MapResponse<TypedRoute, Singleton>>): unknown
|
|
1092
913
|
mapResponse(
|
|
1093
914
|
options: MacroOptions,
|
|
1094
|
-
fn: MaybeArray<MapResponse<TypedRoute, Singleton
|
|
915
|
+
fn: MaybeArray<MapResponse<TypedRoute, Singleton>>,
|
|
1095
916
|
): unknown
|
|
1096
917
|
|
|
1097
918
|
onAfterResponse(
|
|
1098
|
-
fn: MaybeArray<AfterResponseHandler<TypedRoute, Singleton
|
|
919
|
+
fn: MaybeArray<AfterResponseHandler<TypedRoute, Singleton>>,
|
|
1099
920
|
): unknown
|
|
1100
921
|
onAfterResponse(
|
|
1101
922
|
options: MacroOptions,
|
|
1102
|
-
fn: MaybeArray<AfterResponseHandler<TypedRoute, Singleton
|
|
923
|
+
fn: MaybeArray<AfterResponseHandler<TypedRoute, Singleton>>,
|
|
1103
924
|
): unknown
|
|
1104
925
|
|
|
1105
926
|
events: {
|
|
@@ -1114,7 +935,7 @@ export type MacroQueue = HookContainer<
|
|
|
1114
935
|
|
|
1115
936
|
type _CreateEden<
|
|
1116
937
|
Path extends string,
|
|
1117
|
-
Property extends Record<string, unknown> = {}
|
|
938
|
+
Property extends Record<string, unknown> = {},
|
|
1118
939
|
> = Path extends `${infer Start}/${infer Rest}`
|
|
1119
940
|
? {
|
|
1120
941
|
[x in Start]: _CreateEden<Rest, Property>
|
|
@@ -1125,20 +946,23 @@ type _CreateEden<
|
|
|
1125
946
|
|
|
1126
947
|
export type CreateEden<
|
|
1127
948
|
Path extends string,
|
|
1128
|
-
Property extends Record<string, unknown> = {}
|
|
949
|
+
Property extends Record<string, unknown> = {},
|
|
1129
950
|
> = Path extends `/${infer Rest}`
|
|
1130
951
|
? _CreateEden<Rest, Property>
|
|
1131
952
|
: Path extends ''
|
|
1132
953
|
? _CreateEden<'index', Property>
|
|
1133
954
|
: _CreateEden<Path, Property>
|
|
1134
955
|
|
|
1135
|
-
export type
|
|
956
|
+
export type ComposeSpiceflowResponse<Response, Handle> = Handle extends (
|
|
1136
957
|
...a: any[]
|
|
1137
958
|
) => infer A
|
|
1138
|
-
?
|
|
1139
|
-
:
|
|
959
|
+
? _ComposeSpiceflowResponse<Response, Replace<Awaited<A>, BunFile, File>>
|
|
960
|
+
: _ComposeSpiceflowResponse<
|
|
961
|
+
Response,
|
|
962
|
+
Replace<Awaited<Handle>, BunFile, File>
|
|
963
|
+
>
|
|
1140
964
|
|
|
1141
|
-
type
|
|
965
|
+
type _ComposeSpiceflowResponse<Response, Handle> = Prettify<
|
|
1142
966
|
{} extends Response
|
|
1143
967
|
? {
|
|
1144
968
|
200: Exclude<Handle, { [ELYSIA_RESPONSE]: any }>
|
|
@@ -1155,8 +979,8 @@ type _ComposeElysiaResponse<Response, Handle> = Prettify<
|
|
|
1155
979
|
: Response
|
|
1156
980
|
>
|
|
1157
981
|
|
|
1158
|
-
export type
|
|
1159
|
-
Instances extends
|
|
982
|
+
export type MergeSpiceflowInstances<
|
|
983
|
+
Instances extends Spiceflow<any, any, any, any, any, any>[] = [],
|
|
1160
984
|
Prefix extends string = '',
|
|
1161
985
|
Scoped extends boolean = false,
|
|
1162
986
|
Singleton extends SingletonBase = {
|
|
@@ -1174,13 +998,13 @@ export type MergeElysiaInstances<
|
|
|
1174
998
|
macro: {}
|
|
1175
999
|
macroFn: {}
|
|
1176
1000
|
},
|
|
1177
|
-
Routes extends RouteBase = {}
|
|
1001
|
+
Routes extends RouteBase = {},
|
|
1178
1002
|
> = Instances extends [
|
|
1179
|
-
infer Current extends
|
|
1180
|
-
...infer Rest extends
|
|
1003
|
+
infer Current extends Spiceflow<any, any, any, any, any, any>,
|
|
1004
|
+
...infer Rest extends Spiceflow<any, any, any, any, any, any>[],
|
|
1181
1005
|
]
|
|
1182
1006
|
? Current['_types']['Scoped'] extends true
|
|
1183
|
-
?
|
|
1007
|
+
? MergeSpiceflowInstances<
|
|
1184
1008
|
Rest,
|
|
1185
1009
|
Prefix,
|
|
1186
1010
|
Scoped,
|
|
@@ -1189,7 +1013,7 @@ export type MergeElysiaInstances<
|
|
|
1189
1013
|
Metadata,
|
|
1190
1014
|
Routes
|
|
1191
1015
|
>
|
|
1192
|
-
:
|
|
1016
|
+
: MergeSpiceflowInstances<
|
|
1193
1017
|
Rest,
|
|
1194
1018
|
Prefix,
|
|
1195
1019
|
Scoped,
|
|
@@ -1201,7 +1025,7 @@ export type MergeElysiaInstances<
|
|
|
1201
1025
|
? Current['_routes']
|
|
1202
1026
|
: AddPrefix<Prefix, Current['_routes']>)
|
|
1203
1027
|
>
|
|
1204
|
-
:
|
|
1028
|
+
: Spiceflow<
|
|
1205
1029
|
Prefix,
|
|
1206
1030
|
Scoped,
|
|
1207
1031
|
{
|
|
@@ -1225,15 +1049,15 @@ export type MergeElysiaInstances<
|
|
|
1225
1049
|
export type LifeCycleType = 'global' | 'local' | 'scoped'
|
|
1226
1050
|
|
|
1227
1051
|
// Exclude return error()
|
|
1228
|
-
export type
|
|
1052
|
+
export type ExcludeSpiceflowResponse<T> = Exclude<
|
|
1229
1053
|
undefined extends Awaited<T> ? Partial<Awaited<T>> : Awaited<T>,
|
|
1230
1054
|
{ [ELYSIA_RESPONSE]: any }
|
|
1231
1055
|
>
|
|
1232
1056
|
|
|
1233
1057
|
export type InferContext<
|
|
1234
|
-
T extends
|
|
1058
|
+
T extends Spiceflow<any, any, any, any, any, any, any, any>,
|
|
1235
1059
|
Path extends string = T['_types']['Prefix'],
|
|
1236
|
-
Schema extends RouteSchema = T['_types']['Metadata']['schema']
|
|
1060
|
+
Schema extends RouteSchema = T['_types']['Metadata']['schema'],
|
|
1237
1061
|
> = Context<
|
|
1238
1062
|
MergeSchema<Schema, T['_types']['Metadata']['schema']>,
|
|
1239
1063
|
T['_types']['Singleton'] & {
|
|
@@ -1244,9 +1068,9 @@ export type InferContext<
|
|
|
1244
1068
|
>
|
|
1245
1069
|
|
|
1246
1070
|
export type InferHandler<
|
|
1247
|
-
T extends
|
|
1071
|
+
T extends Spiceflow<any, any, any, any, any, any, any, any>,
|
|
1248
1072
|
Path extends string = T['_types']['Prefix'],
|
|
1249
|
-
Schema extends RouteSchema = T['_types']['Metadata']['schema']
|
|
1073
|
+
Schema extends RouteSchema = T['_types']['Metadata']['schema'],
|
|
1250
1074
|
> = InlineHandler<
|
|
1251
1075
|
MergeSchema<Schema, T['_types']['Metadata']['schema']>,
|
|
1252
1076
|
T['_types']['Singleton'] & {
|
|
@@ -1281,7 +1105,7 @@ export type UnionToIntersect<U> = (
|
|
|
1281
1105
|
|
|
1282
1106
|
export type ResolveMacroContext<
|
|
1283
1107
|
Macro extends BaseMacro,
|
|
1284
|
-
MacroFn extends BaseMacroFn
|
|
1108
|
+
MacroFn extends BaseMacroFn,
|
|
1285
1109
|
> = UnionToIntersect<
|
|
1286
1110
|
{
|
|
1287
1111
|
[K in keyof Macro]-?: undefined extends Macro[K]
|
|
@@ -1300,10 +1124,10 @@ export type ResolveMacroContext<
|
|
|
1300
1124
|
export type ContextAppendType = 'append' | 'override'
|
|
1301
1125
|
|
|
1302
1126
|
export type HigherOrderFunction<
|
|
1303
|
-
T extends (...arg: unknown[]) => Function = (...arg: unknown[]) => Function
|
|
1127
|
+
T extends (...arg: unknown[]) => Function = (...arg: unknown[]) => Function,
|
|
1304
1128
|
> = (fn: T, request: Request) => ReturnType<T>
|
|
1305
1129
|
|
|
1306
|
-
// new
|
|
1130
|
+
// new Spiceflow()
|
|
1307
1131
|
// .wrap((fn) => {
|
|
1308
1132
|
// return fn()
|
|
1309
1133
|
// })
|
|
@@ -1387,7 +1211,7 @@ export type HTTPHeaders = Record<string, string> & {
|
|
|
1387
1211
|
|
|
1388
1212
|
// Response context
|
|
1389
1213
|
allow?: string
|
|
1390
|
-
server?: '
|
|
1214
|
+
server?: 'spiceflow' | (string & {})
|
|
1391
1215
|
|
|
1392
1216
|
// Range requests
|
|
1393
1217
|
'accept-ranges'?: string
|
|
@@ -1438,7 +1262,7 @@ export type HTTPHeaders = Record<string, string> & {
|
|
|
1438
1262
|
'x-forwarded-for'?: string
|
|
1439
1263
|
'x-forwarded-host'?: string
|
|
1440
1264
|
'x-forwarded-proto'?: string
|
|
1441
|
-
'x-powered-by'?: '
|
|
1265
|
+
'x-powered-by'?: 'spiceflow' | (string & {})
|
|
1442
1266
|
'x-request-id'?: string
|
|
1443
1267
|
'x-requested-with'?: string
|
|
1444
1268
|
'x-robots-tag'?: string
|