spiceflow 1.1.3 → 1.1.4
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 +54 -23
- package/dist/context.d.ts +9 -23
- package/dist/context.d.ts.map +1 -1
- package/dist/middleware.test.js +27 -0
- package/dist/middleware.test.js.map +1 -1
- package/dist/openapi.d.ts +1 -1
- package/dist/spiceflow.d.ts +5 -5
- package/dist/spiceflow.d.ts.map +1 -1
- package/dist/spiceflow.js +25 -25
- package/dist/spiceflow.js.map +1 -1
- package/dist/spiceflow.test.js +43 -4
- package/dist/spiceflow.test.js.map +1 -1
- package/dist/types.d.ts +20 -20
- package/package.json +1 -1
- package/src/context.ts +10 -28
- package/src/middleware.test.ts +29 -0
- package/src/spiceflow.test.ts +57 -4
- package/src/spiceflow.ts +32 -40
- package/src/types.ts +21 -21
package/src/types.ts
CHANGED
|
@@ -144,7 +144,7 @@ export type Reconcile<
|
|
|
144
144
|
: never
|
|
145
145
|
|
|
146
146
|
export interface SingletonBase {
|
|
147
|
-
|
|
147
|
+
state: Record<string, unknown>
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
export interface DefinitionBase {
|
|
@@ -311,7 +311,7 @@ export interface MergeSchema<
|
|
|
311
311
|
export type Handler<
|
|
312
312
|
in out Route extends RouteSchema = {},
|
|
313
313
|
in out Singleton extends SingletonBase = {
|
|
314
|
-
|
|
314
|
+
state: {}
|
|
315
315
|
},
|
|
316
316
|
Path extends string = '',
|
|
317
317
|
> = (
|
|
@@ -351,7 +351,7 @@ export type CoExist<Original, Target, With> = IsAny<Target> extends true
|
|
|
351
351
|
export type InlineHandler<
|
|
352
352
|
Route extends RouteSchema = {},
|
|
353
353
|
Singleton extends SingletonBase = {
|
|
354
|
-
|
|
354
|
+
state: {}
|
|
355
355
|
},
|
|
356
356
|
Path extends string = '',
|
|
357
357
|
MacroContext = {},
|
|
@@ -383,7 +383,7 @@ export type InlineHandler<
|
|
|
383
383
|
export type OptionalHandler<
|
|
384
384
|
in out Route extends RouteSchema = {},
|
|
385
385
|
in out Singleton extends SingletonBase = {
|
|
386
|
-
|
|
386
|
+
state: {}
|
|
387
387
|
},
|
|
388
388
|
Path extends string = '',
|
|
389
389
|
> = Handler<Route, Singleton, Path> extends (
|
|
@@ -395,7 +395,7 @@ export type OptionalHandler<
|
|
|
395
395
|
export type AfterHandler<
|
|
396
396
|
in out Route extends RouteSchema = {},
|
|
397
397
|
in out Singleton extends SingletonBase = {
|
|
398
|
-
|
|
398
|
+
state: {}
|
|
399
399
|
},
|
|
400
400
|
Path extends string = '',
|
|
401
401
|
> = Handler<Route, Singleton, Path> extends (
|
|
@@ -413,7 +413,7 @@ export type AfterHandler<
|
|
|
413
413
|
export type MapResponse<
|
|
414
414
|
in out Route extends RouteSchema = {},
|
|
415
415
|
in out Singleton extends SingletonBase = {
|
|
416
|
-
|
|
416
|
+
state: {}
|
|
417
417
|
},
|
|
418
418
|
Path extends string = '',
|
|
419
419
|
> = Handler<
|
|
@@ -431,14 +431,14 @@ export type MapResponse<
|
|
|
431
431
|
export type VoidHandler<
|
|
432
432
|
in out Route extends RouteSchema = {},
|
|
433
433
|
in out Singleton extends SingletonBase = {
|
|
434
|
-
|
|
434
|
+
state: {}
|
|
435
435
|
},
|
|
436
436
|
> = (context: Context<Route, Singleton>) => MaybePromise<void>
|
|
437
437
|
|
|
438
438
|
export type TransformHandler<
|
|
439
439
|
in out Route extends RouteSchema = {},
|
|
440
440
|
in out Singleton extends SingletonBase = {
|
|
441
|
-
|
|
441
|
+
state: {}
|
|
442
442
|
},
|
|
443
443
|
BasePath extends string = '',
|
|
444
444
|
> = {
|
|
@@ -458,7 +458,7 @@ export type TransformHandler<
|
|
|
458
458
|
export type BodyHandler<
|
|
459
459
|
in out Route extends RouteSchema = {},
|
|
460
460
|
in out Singleton extends SingletonBase = {
|
|
461
|
-
|
|
461
|
+
state: {}
|
|
462
462
|
},
|
|
463
463
|
Path extends string = '',
|
|
464
464
|
> = (
|
|
@@ -474,7 +474,7 @@ export type BodyHandler<
|
|
|
474
474
|
export type MiddlewareHandler<
|
|
475
475
|
in out Route extends RouteSchema = {},
|
|
476
476
|
in out Singleton extends SingletonBase = {
|
|
477
|
-
|
|
477
|
+
state: {}
|
|
478
478
|
},
|
|
479
479
|
> = (
|
|
480
480
|
context: MiddlewareContext<Singleton>,
|
|
@@ -484,7 +484,7 @@ export type MiddlewareHandler<
|
|
|
484
484
|
export type AfterResponseHandler<
|
|
485
485
|
in out Route extends RouteSchema = {},
|
|
486
486
|
in out Singleton extends SingletonBase = {
|
|
487
|
-
|
|
487
|
+
state: {}
|
|
488
488
|
},
|
|
489
489
|
> = (
|
|
490
490
|
context: Prettify<
|
|
@@ -502,13 +502,13 @@ export type ErrorHandler<
|
|
|
502
502
|
in out T extends Record<string, Error> = {},
|
|
503
503
|
in out Route extends RouteSchema = {},
|
|
504
504
|
in out Singleton extends SingletonBase = {
|
|
505
|
-
|
|
505
|
+
state: {}
|
|
506
506
|
},
|
|
507
507
|
> = (
|
|
508
508
|
context: ErrorContext<
|
|
509
509
|
Route,
|
|
510
510
|
{
|
|
511
|
-
|
|
511
|
+
state: Singleton['state']
|
|
512
512
|
}
|
|
513
513
|
> &
|
|
514
514
|
(
|
|
@@ -517,35 +517,35 @@ export type ErrorHandler<
|
|
|
517
517
|
request: Request
|
|
518
518
|
code: 'UNKNOWN'
|
|
519
519
|
error: Readonly<Error>
|
|
520
|
-
} & Partial<Singleton['
|
|
520
|
+
} & Partial<Singleton['state']>
|
|
521
521
|
>
|
|
522
522
|
| Prettify<
|
|
523
523
|
{
|
|
524
524
|
request: Request
|
|
525
525
|
code: 'VALIDATION'
|
|
526
526
|
error: Readonly<ValidationError>
|
|
527
|
-
} & Singleton['
|
|
527
|
+
} & Singleton['state']
|
|
528
528
|
>
|
|
529
529
|
// | Prettify<
|
|
530
530
|
// {
|
|
531
531
|
// request: Request
|
|
532
532
|
// code: 'NOT_FOUND'
|
|
533
533
|
// error: Readonly<NotFoundError>
|
|
534
|
-
// } & NeverKey<Singleton['
|
|
534
|
+
// } & NeverKey<Singleton['state']>
|
|
535
535
|
// >
|
|
536
536
|
| Prettify<
|
|
537
537
|
{
|
|
538
538
|
request: Request
|
|
539
539
|
code: 'PARSE'
|
|
540
540
|
error: Readonly<ParseError>
|
|
541
|
-
} & Singleton['
|
|
541
|
+
} & Singleton['state']
|
|
542
542
|
>
|
|
543
543
|
| Prettify<
|
|
544
544
|
{
|
|
545
545
|
request: Request
|
|
546
546
|
code: 'INTERNAL_SERVER_ERROR'
|
|
547
547
|
error: Readonly<InternalServerError>
|
|
548
|
-
} & Partial<Singleton['
|
|
548
|
+
} & Partial<Singleton['state']>
|
|
549
549
|
>
|
|
550
550
|
| Prettify<
|
|
551
551
|
{
|
|
@@ -555,7 +555,7 @@ export type ErrorHandler<
|
|
|
555
555
|
error: Readonly<T[K]>
|
|
556
556
|
}
|
|
557
557
|
}[keyof T] &
|
|
558
|
-
Partial<Singleton['
|
|
558
|
+
Partial<Singleton['state']>
|
|
559
559
|
>
|
|
560
560
|
),
|
|
561
561
|
) => any | Promise<any>
|
|
@@ -689,7 +689,7 @@ export type MergeSpiceflowInstances<
|
|
|
689
689
|
Prefix extends string = '',
|
|
690
690
|
Scoped extends boolean = false,
|
|
691
691
|
Singleton extends SingletonBase = {
|
|
692
|
-
|
|
692
|
+
state: {}
|
|
693
693
|
},
|
|
694
694
|
Definitions extends DefinitionBase = {
|
|
695
695
|
type: {}
|
|
@@ -731,7 +731,7 @@ export type MergeSpiceflowInstances<
|
|
|
731
731
|
Prefix,
|
|
732
732
|
Scoped,
|
|
733
733
|
{
|
|
734
|
-
|
|
734
|
+
state: Prettify<Singleton['state']>
|
|
735
735
|
},
|
|
736
736
|
{
|
|
737
737
|
type: Prettify<Definitions['type']>
|