spiceflow 1.0.1 → 1.0.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/README.md +148 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/types.d.ts +2 -6
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client.test.js +26 -22
- package/dist/client.test.js.map +1 -1
- package/dist/elysia-fork/context.d.ts +6 -22
- package/dist/elysia-fork/context.d.ts.map +1 -1
- package/dist/elysia-fork/error.d.ts +2 -226
- package/dist/elysia-fork/error.d.ts.map +1 -1
- package/dist/elysia-fork/error.js +13 -166
- package/dist/elysia-fork/error.js.map +1 -1
- package/dist/elysia-fork/types.d.ts +20 -30
- 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/openapi.d.ts +67 -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 +35 -23
- package/dist/spiceflow.d.ts.map +1 -1
- package/dist/spiceflow.js +214 -111
- package/dist/spiceflow.js.map +1 -1
- package/dist/spiceflow.test.js +135 -31
- package/dist/spiceflow.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 +61 -0
- package/dist/zod.test.js.map +1 -0
- package/package.json +7 -3
- package/src/client/types.ts +14 -19
- package/src/client.test.ts +34 -25
- package/src/elysia-fork/context.ts +19 -49
- package/src/elysia-fork/error.ts +6 -259
- package/src/elysia-fork/types.ts +115 -188
- package/src/openapi.ts +426 -0
- package/src/spiceflow.test.ts +188 -51
- package/src/spiceflow.ts +312 -183
- package/src/zod.test.ts +73 -0
package/src/elysia-fork/types.ts
CHANGED
|
@@ -1,34 +1,31 @@
|
|
|
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
6
|
import type {
|
|
8
|
-
|
|
9
|
-
TObject,
|
|
7
|
+
OptionalKind,
|
|
10
8
|
Static,
|
|
11
|
-
TAnySchema,
|
|
12
|
-
TNull,
|
|
13
|
-
TUndefined,
|
|
14
9
|
StaticDecode,
|
|
15
|
-
|
|
10
|
+
TAnySchema,
|
|
11
|
+
TObject,
|
|
12
|
+
TSchema,
|
|
16
13
|
} from '@sinclair/typebox'
|
|
17
14
|
import type { TypeCheck, ValueError } from '@sinclair/typebox/compiler'
|
|
15
|
+
import type { BunFile, Server } from 'bun'
|
|
18
16
|
|
|
19
17
|
import type { OpenAPIV3 } from 'openapi-types'
|
|
20
18
|
|
|
19
|
+
import { Spiceflow } from '../spiceflow'
|
|
21
20
|
import type { Context, ErrorContext, PreContext } from './context'
|
|
22
21
|
import {
|
|
23
22
|
ELYSIA_RESPONSE,
|
|
24
23
|
InternalServerError,
|
|
25
|
-
InvalidCookieSignature,
|
|
26
24
|
NotFoundError,
|
|
27
25
|
ParseError,
|
|
28
|
-
ValidationError
|
|
26
|
+
ValidationError,
|
|
29
27
|
} from './error'
|
|
30
|
-
import {
|
|
31
|
-
|
|
28
|
+
import { ZodTypeAny, ZodObject } from 'zod'
|
|
32
29
|
|
|
33
30
|
export type MaybeArray<T> = T | T[]
|
|
34
31
|
export type MaybePromise<T> = T | Promise<T>
|
|
@@ -93,7 +90,7 @@ export type Reconcile<
|
|
|
93
90
|
B extends Object,
|
|
94
91
|
Override extends boolean = false,
|
|
95
92
|
// Detect Stack limit, eg. circular dependency
|
|
96
|
-
Stack extends number[] = []
|
|
93
|
+
Stack extends number[] = [],
|
|
97
94
|
> = Stack['length'] extends 16
|
|
98
95
|
? A
|
|
99
96
|
: Override extends true
|
|
@@ -177,10 +174,10 @@ export interface MetadataBase {
|
|
|
177
174
|
|
|
178
175
|
export interface RouteSchema {
|
|
179
176
|
body?: unknown
|
|
180
|
-
headers?: unknown
|
|
177
|
+
// headers?: unknown
|
|
181
178
|
query?: unknown
|
|
182
179
|
params?: unknown
|
|
183
|
-
cookie?: unknown
|
|
180
|
+
// cookie?: unknown
|
|
184
181
|
response?: unknown
|
|
185
182
|
}
|
|
186
183
|
|
|
@@ -188,11 +185,17 @@ type OptionalField = {
|
|
|
188
185
|
[OptionalKind]: 'Optional'
|
|
189
186
|
}
|
|
190
187
|
|
|
188
|
+
export type TypeSchema = TSchema | ZodTypeAny
|
|
189
|
+
|
|
190
|
+
export type TypeObject = TObject | ZodObject<any, any, any>
|
|
191
|
+
|
|
191
192
|
export type UnwrapSchema<
|
|
192
|
-
Schema extends
|
|
193
|
-
Definitions extends Record<string, unknown> = {}
|
|
193
|
+
Schema extends TypeSchema | string | undefined,
|
|
194
|
+
Definitions extends Record<string, unknown> = {},
|
|
194
195
|
> = undefined extends Schema
|
|
195
196
|
? unknown
|
|
197
|
+
: Schema extends ZodTypeAny
|
|
198
|
+
? z.infer<Schema>
|
|
196
199
|
: Schema extends TSchema
|
|
197
200
|
? Schema extends OptionalField
|
|
198
201
|
? Prettify<Partial<Static<Schema>>>
|
|
@@ -203,31 +206,16 @@ export type UnwrapSchema<
|
|
|
203
206
|
: Definitions
|
|
204
207
|
: unknown
|
|
205
208
|
|
|
206
|
-
export type UnwrapBodySchema<
|
|
207
|
-
Schema extends TSchema | string | undefined,
|
|
208
|
-
Definitions extends Record<string, unknown> = {}
|
|
209
|
-
> = undefined extends Schema
|
|
210
|
-
? unknown
|
|
211
|
-
: Schema extends TSchema
|
|
212
|
-
? Schema extends OptionalField
|
|
213
|
-
? Prettify<Partial<Static<Schema>>> | null
|
|
214
|
-
: StaticDecode<Schema>
|
|
215
|
-
: Schema extends string
|
|
216
|
-
? Definitions extends Record<Schema, infer NamedSchema>
|
|
217
|
-
? NamedSchema
|
|
218
|
-
: Definitions
|
|
219
|
-
: unknown
|
|
220
|
-
|
|
221
209
|
export interface UnwrapRoute<
|
|
222
210
|
in out Schema extends InputSchema<any>,
|
|
223
|
-
in out Definitions extends DefinitionBase['type'] = {}
|
|
211
|
+
in out Definitions extends DefinitionBase['type'] = {},
|
|
224
212
|
> {
|
|
225
|
-
body:
|
|
213
|
+
body: UnwrapSchema<Schema['body'], Definitions>
|
|
226
214
|
// headers: UnwrapSchema<Schema['headers'], Definitions>
|
|
227
|
-
|
|
228
|
-
|
|
215
|
+
query: UnwrapSchema<Schema['query'], Definitions>
|
|
216
|
+
params: UnwrapSchema<Schema['params'], Definitions>
|
|
229
217
|
// cookie: UnwrapSchema<Schema['cookie'], Definitions>
|
|
230
|
-
response: Schema['response'] extends
|
|
218
|
+
response: Schema['response'] extends TypeSchema | string
|
|
231
219
|
? {
|
|
232
220
|
200: CoExist<
|
|
233
221
|
UnwrapSchema<Schema['response'], Definitions>,
|
|
@@ -235,7 +223,7 @@ export interface UnwrapRoute<
|
|
|
235
223
|
BunFile
|
|
236
224
|
>
|
|
237
225
|
}
|
|
238
|
-
: Schema['response'] extends Record<number,
|
|
226
|
+
: Schema['response'] extends Record<number, TypeSchema | string>
|
|
239
227
|
? {
|
|
240
228
|
[k in keyof Schema['response']]: CoExist<
|
|
241
229
|
UnwrapSchema<Schema['response'][k], Definitions>,
|
|
@@ -246,50 +234,6 @@ export interface UnwrapRoute<
|
|
|
246
234
|
: unknown | void
|
|
247
235
|
}
|
|
248
236
|
|
|
249
|
-
// export interface UnwrapGroupGuardRoute<
|
|
250
|
-
// in out Schema extends InputSchema<any>,
|
|
251
|
-
// in out Definitions extends Record<string, unknown> = {},
|
|
252
|
-
// Path extends string = ''
|
|
253
|
-
// > {
|
|
254
|
-
// body: UnwrapBodySchema<Schema['body'], Definitions>
|
|
255
|
-
// headers: UnwrapSchema<
|
|
256
|
-
// Schema['headers'],
|
|
257
|
-
// Definitions
|
|
258
|
-
// > extends infer A extends Record<string, unknown>
|
|
259
|
-
// ? A
|
|
260
|
-
// : undefined
|
|
261
|
-
// query: UnwrapSchema<
|
|
262
|
-
// Schema['query'],
|
|
263
|
-
// Definitions
|
|
264
|
-
// > extends infer A extends Record<string, unknown>
|
|
265
|
-
// ? A
|
|
266
|
-
// : undefined
|
|
267
|
-
// params: UnwrapSchema<
|
|
268
|
-
// Schema['params'],
|
|
269
|
-
// Definitions
|
|
270
|
-
// > extends infer A extends Record<string, unknown>
|
|
271
|
-
// ? A
|
|
272
|
-
// : Path extends `${string}/${':' | '*'}${string}`
|
|
273
|
-
// ? Record<GetPathParameter<Path>, string>
|
|
274
|
-
// : never
|
|
275
|
-
// cookie: UnwrapSchema<
|
|
276
|
-
// Schema['cookie'],
|
|
277
|
-
// Definitions
|
|
278
|
-
// > extends infer A extends Record<string, unknown>
|
|
279
|
-
// ? A
|
|
280
|
-
// : undefined
|
|
281
|
-
// response: Schema['response'] extends TSchema | string
|
|
282
|
-
// ? UnwrapSchema<Schema['response'], Definitions>
|
|
283
|
-
// : Schema['response'] extends {
|
|
284
|
-
// [k in string]: TSchema | string
|
|
285
|
-
// }
|
|
286
|
-
// ? UnwrapSchema<
|
|
287
|
-
// Schema['response'][keyof Schema['response']],
|
|
288
|
-
// Definitions
|
|
289
|
-
// >
|
|
290
|
-
// : unknown | void
|
|
291
|
-
// }
|
|
292
|
-
|
|
293
237
|
export type HookContainer<T extends Function = Function> = {
|
|
294
238
|
checksum?: number
|
|
295
239
|
scope?: LifeCycleType
|
|
@@ -376,27 +320,27 @@ export type HTTPMethod =
|
|
|
376
320
|
| 'ALL'
|
|
377
321
|
|
|
378
322
|
export interface InputSchema<Name extends string = string> {
|
|
379
|
-
body?:
|
|
323
|
+
body?: TypeSchema | Name
|
|
380
324
|
// headers?: TObject | TNull | TUndefined | Name
|
|
381
|
-
|
|
382
|
-
|
|
325
|
+
query?: TypeObject | Name
|
|
326
|
+
params?: TypeObject | Name
|
|
383
327
|
// cookie?: TObject | TNull | TUndefined | Name
|
|
384
328
|
response?:
|
|
385
|
-
|
|
|
386
|
-
| Record<number,
|
|
329
|
+
| TypeSchema
|
|
330
|
+
| Record<number, TypeSchema>
|
|
387
331
|
| Name
|
|
388
|
-
| Record<number, Name |
|
|
332
|
+
| Record<number, Name | TypeSchema>
|
|
389
333
|
}
|
|
390
334
|
|
|
391
335
|
export interface MergeSchema<
|
|
392
336
|
in out A extends RouteSchema,
|
|
393
|
-
in out B extends RouteSchema
|
|
337
|
+
in out B extends RouteSchema,
|
|
394
338
|
> {
|
|
395
339
|
body: undefined extends A['body'] ? B['body'] : A['body']
|
|
396
|
-
headers: undefined extends A['headers'] ? B['headers'] : A['headers']
|
|
340
|
+
// headers: undefined extends A['headers'] ? B['headers'] : A['headers']
|
|
397
341
|
query: undefined extends A['query'] ? B['query'] : A['query']
|
|
398
342
|
params: undefined extends A['params'] ? B['params'] : A['params']
|
|
399
|
-
cookie: undefined extends A['cookie'] ? B['cookie'] : A['cookie']
|
|
343
|
+
// cookie: undefined extends A['cookie'] ? B['cookie'] : A['cookie']
|
|
400
344
|
response: {} extends A['response']
|
|
401
345
|
? {} extends B['response']
|
|
402
346
|
? {}
|
|
@@ -414,9 +358,9 @@ export type Handler<
|
|
|
414
358
|
derive: {}
|
|
415
359
|
resolve: {}
|
|
416
360
|
},
|
|
417
|
-
Path extends string = ''
|
|
361
|
+
Path extends string = '',
|
|
418
362
|
> = (
|
|
419
|
-
context: Context<Route, Singleton, Path
|
|
363
|
+
context: Context<Route, Singleton, Path>,
|
|
420
364
|
) => MaybePromise<
|
|
421
365
|
{} extends Route['response']
|
|
422
366
|
? unknown
|
|
@@ -458,48 +402,31 @@ export type InlineHandler<
|
|
|
458
402
|
resolve: {}
|
|
459
403
|
},
|
|
460
404
|
Path extends string = '',
|
|
461
|
-
MacroContext = {}
|
|
462
|
-
> =
|
|
463
|
-
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
[ELYSIA_RESPONSE]: Status
|
|
487
|
-
}
|
|
488
|
-
}[keyof Route['response']]
|
|
489
|
-
>)
|
|
490
|
-
| ({} extends Route['response']
|
|
491
|
-
? string | number | boolean | Object
|
|
492
|
-
:
|
|
493
|
-
| (Route['response'] extends { 200: any }
|
|
494
|
-
? Route['response']
|
|
495
|
-
: string | number | boolean | Object)
|
|
496
|
-
| Route['response'][keyof Route['response']]
|
|
497
|
-
| {
|
|
498
|
-
[Status in keyof Route['response']]: {
|
|
499
|
-
_type: Record<Status, Route['response'][Status]>
|
|
500
|
-
[ELYSIA_RESPONSE]: Status
|
|
501
|
-
}
|
|
502
|
-
}[keyof Route['response']])
|
|
405
|
+
MacroContext = {},
|
|
406
|
+
> = (
|
|
407
|
+
context: MacroContext extends Record<string | number | symbol, unknown>
|
|
408
|
+
? Prettify<MacroContext & Context<Route, Singleton, Path>>
|
|
409
|
+
: Context<Route, Singleton, Path>,
|
|
410
|
+
) =>
|
|
411
|
+
| Response
|
|
412
|
+
| MaybePromise<
|
|
413
|
+
{} extends Route['response']
|
|
414
|
+
? unknown
|
|
415
|
+
:
|
|
416
|
+
| (Route['response'] extends { 200: any }
|
|
417
|
+
? Route['response']
|
|
418
|
+
: string | number | boolean | Object)
|
|
419
|
+
| Route['response'][keyof Route['response']]
|
|
420
|
+
| {
|
|
421
|
+
[Status in keyof Route['response']]: {
|
|
422
|
+
_type: Record<
|
|
423
|
+
Status,
|
|
424
|
+
Route['response'][Status]
|
|
425
|
+
>
|
|
426
|
+
[ELYSIA_RESPONSE]: Status
|
|
427
|
+
}
|
|
428
|
+
}[keyof Route['response']]
|
|
429
|
+
>
|
|
503
430
|
|
|
504
431
|
export type OptionalHandler<
|
|
505
432
|
in out Route extends RouteSchema = {},
|
|
@@ -509,9 +436,9 @@ export type OptionalHandler<
|
|
|
509
436
|
derive: {}
|
|
510
437
|
resolve: {}
|
|
511
438
|
},
|
|
512
|
-
Path extends string = ''
|
|
439
|
+
Path extends string = '',
|
|
513
440
|
> = Handler<Route, Singleton, Path> extends (
|
|
514
|
-
context: infer Context
|
|
441
|
+
context: infer Context,
|
|
515
442
|
) => infer Returned
|
|
516
443
|
? (context: Context) => Returned | MaybePromise<void>
|
|
517
444
|
: never
|
|
@@ -524,16 +451,16 @@ export type AfterHandler<
|
|
|
524
451
|
derive: {}
|
|
525
452
|
resolve: {}
|
|
526
453
|
},
|
|
527
|
-
Path extends string = ''
|
|
454
|
+
Path extends string = '',
|
|
528
455
|
> = Handler<Route, Singleton, Path> extends (
|
|
529
|
-
context: infer Context
|
|
456
|
+
context: infer Context,
|
|
530
457
|
) => infer Returned
|
|
531
458
|
? (
|
|
532
459
|
context: Prettify<
|
|
533
460
|
{
|
|
534
461
|
response: Route['response']
|
|
535
462
|
} & Context
|
|
536
|
-
|
|
463
|
+
>,
|
|
537
464
|
) => Returned | MaybePromise<void>
|
|
538
465
|
: never
|
|
539
466
|
|
|
@@ -545,7 +472,7 @@ export type MapResponse<
|
|
|
545
472
|
derive: {}
|
|
546
473
|
resolve: {}
|
|
547
474
|
},
|
|
548
|
-
Path extends string = ''
|
|
475
|
+
Path extends string = '',
|
|
549
476
|
> = Handler<
|
|
550
477
|
Omit<Route, 'response'> & {
|
|
551
478
|
response: MaybePromise<Response | undefined | unknown>
|
|
@@ -565,7 +492,7 @@ export type VoidHandler<
|
|
|
565
492
|
store: {}
|
|
566
493
|
derive: {}
|
|
567
494
|
resolve: {}
|
|
568
|
-
}
|
|
495
|
+
},
|
|
569
496
|
> = (context: Context<Route, Singleton>) => MaybePromise<void>
|
|
570
497
|
|
|
571
498
|
export type TransformHandler<
|
|
@@ -576,7 +503,7 @@ export type TransformHandler<
|
|
|
576
503
|
derive: {}
|
|
577
504
|
resolve: {}
|
|
578
505
|
},
|
|
579
|
-
BasePath extends string = ''
|
|
506
|
+
BasePath extends string = '',
|
|
580
507
|
> = {
|
|
581
508
|
(
|
|
582
509
|
context: Prettify<
|
|
@@ -587,7 +514,7 @@ export type TransformHandler<
|
|
|
587
514
|
},
|
|
588
515
|
BasePath
|
|
589
516
|
>
|
|
590
|
-
|
|
517
|
+
>,
|
|
591
518
|
): MaybePromise<void>
|
|
592
519
|
}
|
|
593
520
|
|
|
@@ -599,7 +526,7 @@ export type BodyHandler<
|
|
|
599
526
|
derive: {}
|
|
600
527
|
resolve: {}
|
|
601
528
|
},
|
|
602
|
-
Path extends string = ''
|
|
529
|
+
Path extends string = '',
|
|
603
530
|
> = (
|
|
604
531
|
context: Prettify<
|
|
605
532
|
{
|
|
@@ -620,7 +547,7 @@ export type BodyHandler<
|
|
|
620
547
|
* })
|
|
621
548
|
* ```
|
|
622
549
|
*/
|
|
623
|
-
contentType: string
|
|
550
|
+
contentType: string,
|
|
624
551
|
) => MaybePromise<any>
|
|
625
552
|
|
|
626
553
|
export type PreHandler<
|
|
@@ -630,7 +557,7 @@ export type PreHandler<
|
|
|
630
557
|
store: {}
|
|
631
558
|
derive: {}
|
|
632
559
|
resolve: {}
|
|
633
|
-
}
|
|
560
|
+
},
|
|
634
561
|
> = (context: PreContext<Singleton>) => MaybePromise<Route['response'] | void>
|
|
635
562
|
|
|
636
563
|
export type AfterResponseHandler<
|
|
@@ -640,17 +567,17 @@ export type AfterResponseHandler<
|
|
|
640
567
|
store: {}
|
|
641
568
|
derive: {}
|
|
642
569
|
resolve: {}
|
|
643
|
-
}
|
|
570
|
+
},
|
|
644
571
|
> = (
|
|
645
572
|
context: Prettify<
|
|
646
573
|
Context<Route, Singleton> & {
|
|
647
574
|
response: Route['response']
|
|
648
575
|
}
|
|
649
|
-
|
|
576
|
+
>,
|
|
650
577
|
) => MaybePromise<void>
|
|
651
578
|
|
|
652
579
|
export type GracefulHandler<
|
|
653
|
-
in Instance extends Spiceflow<any, any, any, any, any, any, any, any
|
|
580
|
+
in Instance extends Spiceflow<any, any, any, any, any, any, any, any>,
|
|
654
581
|
> = (data: Instance) => any
|
|
655
582
|
|
|
656
583
|
export type ErrorHandler<
|
|
@@ -673,7 +600,7 @@ export type ErrorHandler<
|
|
|
673
600
|
derive: {}
|
|
674
601
|
resolve: {}
|
|
675
602
|
schema: {}
|
|
676
|
-
}
|
|
603
|
+
},
|
|
677
604
|
> = (
|
|
678
605
|
context: ErrorContext<
|
|
679
606
|
Route,
|
|
@@ -761,22 +688,22 @@ export type ErrorHandler<
|
|
|
761
688
|
Volatile['resolve']
|
|
762
689
|
>
|
|
763
690
|
>
|
|
764
|
-
| Prettify<
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
691
|
+
// | Prettify<
|
|
692
|
+
// {
|
|
693
|
+
// request: Request
|
|
694
|
+
// code: 'INVALID_COOKIE_SIGNATURE'
|
|
695
|
+
// error: Readonly<InvalidCookieSignature>
|
|
696
|
+
// } & NeverKey<
|
|
697
|
+
// Singleton['derive'] &
|
|
698
|
+
// Ephemeral['derive'] &
|
|
699
|
+
// Volatile['derive']
|
|
700
|
+
// > &
|
|
701
|
+
// NeverKey<
|
|
702
|
+
// Singleton['derive'] &
|
|
703
|
+
// Ephemeral['resolve'] &
|
|
704
|
+
// Volatile['resolve']
|
|
705
|
+
// >
|
|
706
|
+
// >
|
|
780
707
|
| Prettify<
|
|
781
708
|
{
|
|
782
709
|
[K in keyof T]: {
|
|
@@ -796,7 +723,7 @@ export type ErrorHandler<
|
|
|
796
723
|
Volatile['resolve']
|
|
797
724
|
>
|
|
798
725
|
>
|
|
799
|
-
)
|
|
726
|
+
),
|
|
800
727
|
) => any | Promise<any>
|
|
801
728
|
|
|
802
729
|
export type Isolate<T> = {
|
|
@@ -825,7 +752,7 @@ export type LocalHook<
|
|
|
825
752
|
params: undefined extends Schema['params']
|
|
826
753
|
? ResolvePath<Path>
|
|
827
754
|
: Schema['params']
|
|
828
|
-
}
|
|
755
|
+
},
|
|
829
756
|
> = (LocalSchema extends {} ? LocalSchema : Isolate<LocalSchema>) &
|
|
830
757
|
Extension & {
|
|
831
758
|
/**
|
|
@@ -948,54 +875,54 @@ export interface MacroManager<
|
|
|
948
875
|
derive: {}
|
|
949
876
|
resolve: {}
|
|
950
877
|
},
|
|
951
|
-
in out Errors extends Record<string, Error> = {}
|
|
878
|
+
in out Errors extends Record<string, Error> = {},
|
|
952
879
|
> {
|
|
953
880
|
onParse(fn: MaybeArray<BodyHandler<TypedRoute, Singleton>>): unknown
|
|
954
881
|
onParse(
|
|
955
882
|
options: MacroOptions,
|
|
956
|
-
fn: MaybeArray<BodyHandler<TypedRoute, Singleton
|
|
883
|
+
fn: MaybeArray<BodyHandler<TypedRoute, Singleton>>,
|
|
957
884
|
): unknown
|
|
958
885
|
|
|
959
886
|
onTransform(fn: MaybeArray<VoidHandler<TypedRoute, Singleton>>): unknown
|
|
960
887
|
onTransform(
|
|
961
888
|
options: MacroOptions,
|
|
962
|
-
fn: MaybeArray<VoidHandler<TypedRoute, Singleton
|
|
889
|
+
fn: MaybeArray<VoidHandler<TypedRoute, Singleton>>,
|
|
963
890
|
): unknown
|
|
964
891
|
|
|
965
892
|
onBeforeHandle(
|
|
966
|
-
fn: MaybeArray<OptionalHandler<TypedRoute, Singleton
|
|
893
|
+
fn: MaybeArray<OptionalHandler<TypedRoute, Singleton>>,
|
|
967
894
|
): unknown
|
|
968
895
|
onBeforeHandle(
|
|
969
896
|
options: MacroOptions,
|
|
970
|
-
fn: MaybeArray<OptionalHandler<TypedRoute, Singleton
|
|
897
|
+
fn: MaybeArray<OptionalHandler<TypedRoute, Singleton>>,
|
|
971
898
|
): unknown
|
|
972
899
|
|
|
973
900
|
onAfterHandle(fn: MaybeArray<AfterHandler<TypedRoute, Singleton>>): unknown
|
|
974
901
|
onAfterHandle(
|
|
975
902
|
options: MacroOptions,
|
|
976
|
-
fn: MaybeArray<AfterHandler<TypedRoute, Singleton
|
|
903
|
+
fn: MaybeArray<AfterHandler<TypedRoute, Singleton>>,
|
|
977
904
|
): unknown
|
|
978
905
|
|
|
979
906
|
onError(
|
|
980
|
-
fn: MaybeArray<ErrorHandler<Errors, TypedRoute, Singleton
|
|
907
|
+
fn: MaybeArray<ErrorHandler<Errors, TypedRoute, Singleton>>,
|
|
981
908
|
): unknown
|
|
982
909
|
onError(
|
|
983
910
|
options: MacroOptions,
|
|
984
|
-
fn: MaybeArray<ErrorHandler<Errors, TypedRoute, Singleton
|
|
911
|
+
fn: MaybeArray<ErrorHandler<Errors, TypedRoute, Singleton>>,
|
|
985
912
|
): unknown
|
|
986
913
|
|
|
987
914
|
mapResponse(fn: MaybeArray<MapResponse<TypedRoute, Singleton>>): unknown
|
|
988
915
|
mapResponse(
|
|
989
916
|
options: MacroOptions,
|
|
990
|
-
fn: MaybeArray<MapResponse<TypedRoute, Singleton
|
|
917
|
+
fn: MaybeArray<MapResponse<TypedRoute, Singleton>>,
|
|
991
918
|
): unknown
|
|
992
919
|
|
|
993
920
|
onAfterResponse(
|
|
994
|
-
fn: MaybeArray<AfterResponseHandler<TypedRoute, Singleton
|
|
921
|
+
fn: MaybeArray<AfterResponseHandler<TypedRoute, Singleton>>,
|
|
995
922
|
): unknown
|
|
996
923
|
onAfterResponse(
|
|
997
924
|
options: MacroOptions,
|
|
998
|
-
fn: MaybeArray<AfterResponseHandler<TypedRoute, Singleton
|
|
925
|
+
fn: MaybeArray<AfterResponseHandler<TypedRoute, Singleton>>,
|
|
999
926
|
): unknown
|
|
1000
927
|
|
|
1001
928
|
events: {
|
|
@@ -1010,7 +937,7 @@ export type MacroQueue = HookContainer<
|
|
|
1010
937
|
|
|
1011
938
|
type _CreateEden<
|
|
1012
939
|
Path extends string,
|
|
1013
|
-
Property extends Record<string, unknown> = {}
|
|
940
|
+
Property extends Record<string, unknown> = {},
|
|
1014
941
|
> = Path extends `${infer Start}/${infer Rest}`
|
|
1015
942
|
? {
|
|
1016
943
|
[x in Start]: _CreateEden<Rest, Property>
|
|
@@ -1021,7 +948,7 @@ type _CreateEden<
|
|
|
1021
948
|
|
|
1022
949
|
export type CreateEden<
|
|
1023
950
|
Path extends string,
|
|
1024
|
-
Property extends Record<string, unknown> = {}
|
|
951
|
+
Property extends Record<string, unknown> = {},
|
|
1025
952
|
> = Path extends `/${infer Rest}`
|
|
1026
953
|
? _CreateEden<Rest, Property>
|
|
1027
954
|
: Path extends ''
|
|
@@ -1073,10 +1000,10 @@ export type MergeSpiceflowInstances<
|
|
|
1073
1000
|
macro: {}
|
|
1074
1001
|
macroFn: {}
|
|
1075
1002
|
},
|
|
1076
|
-
Routes extends RouteBase = {}
|
|
1003
|
+
Routes extends RouteBase = {},
|
|
1077
1004
|
> = Instances extends [
|
|
1078
1005
|
infer Current extends Spiceflow<any, any, any, any, any, any>,
|
|
1079
|
-
...infer Rest extends Spiceflow<any, any, any, any, any, any>[]
|
|
1006
|
+
...infer Rest extends Spiceflow<any, any, any, any, any, any>[],
|
|
1080
1007
|
]
|
|
1081
1008
|
? Current['_types']['Scoped'] extends true
|
|
1082
1009
|
? MergeSpiceflowInstances<
|
|
@@ -1132,7 +1059,7 @@ export type ExcludeSpiceflowResponse<T> = Exclude<
|
|
|
1132
1059
|
export type InferContext<
|
|
1133
1060
|
T extends Spiceflow<any, any, any, any, any, any, any, any>,
|
|
1134
1061
|
Path extends string = T['_types']['Prefix'],
|
|
1135
|
-
Schema extends RouteSchema = T['_types']['Metadata']['schema']
|
|
1062
|
+
Schema extends RouteSchema = T['_types']['Metadata']['schema'],
|
|
1136
1063
|
> = Context<
|
|
1137
1064
|
MergeSchema<Schema, T['_types']['Metadata']['schema']>,
|
|
1138
1065
|
T['_types']['Singleton'] & {
|
|
@@ -1145,7 +1072,7 @@ export type InferContext<
|
|
|
1145
1072
|
export type InferHandler<
|
|
1146
1073
|
T extends Spiceflow<any, any, any, any, any, any, any, any>,
|
|
1147
1074
|
Path extends string = T['_types']['Prefix'],
|
|
1148
|
-
Schema extends RouteSchema = T['_types']['Metadata']['schema']
|
|
1075
|
+
Schema extends RouteSchema = T['_types']['Metadata']['schema'],
|
|
1149
1076
|
> = InlineHandler<
|
|
1150
1077
|
MergeSchema<Schema, T['_types']['Metadata']['schema']>,
|
|
1151
1078
|
T['_types']['Singleton'] & {
|
|
@@ -1180,7 +1107,7 @@ export type UnionToIntersect<U> = (
|
|
|
1180
1107
|
|
|
1181
1108
|
export type ResolveMacroContext<
|
|
1182
1109
|
Macro extends BaseMacro,
|
|
1183
|
-
MacroFn extends BaseMacroFn
|
|
1110
|
+
MacroFn extends BaseMacroFn,
|
|
1184
1111
|
> = UnionToIntersect<
|
|
1185
1112
|
{
|
|
1186
1113
|
[K in keyof Macro]-?: undefined extends Macro[K]
|
|
@@ -1199,7 +1126,7 @@ export type ResolveMacroContext<
|
|
|
1199
1126
|
export type ContextAppendType = 'append' | 'override'
|
|
1200
1127
|
|
|
1201
1128
|
export type HigherOrderFunction<
|
|
1202
|
-
T extends (...arg: unknown[]) => Function = (...arg: unknown[]) => Function
|
|
1129
|
+
T extends (...arg: unknown[]) => Function = (...arg: unknown[]) => Function,
|
|
1203
1130
|
> = (fn: T, request: Request) => ReturnType<T>
|
|
1204
1131
|
|
|
1205
1132
|
// new Spiceflow()
|