@effect-app/infra 2.74.0 → 2.76.0
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/CHANGELOG.md +17 -0
- package/dist/api/layerUtils.d.ts +22 -0
- package/dist/api/layerUtils.d.ts.map +1 -0
- package/dist/api/layerUtils.js +2 -0
- package/dist/api/routing/middleware/ContextProvider.d.ts +41 -0
- package/dist/api/routing/middleware/ContextProvider.d.ts.map +1 -0
- package/dist/api/routing/middleware/ContextProvider.js +27 -0
- package/dist/api/routing/middleware/DynamicMiddleware.d.ts +61 -0
- package/dist/api/routing/middleware/DynamicMiddleware.d.ts.map +1 -0
- package/dist/api/routing/middleware/DynamicMiddleware.js +45 -0
- package/dist/api/routing/middleware/dynamic-middleware.d.ts +25 -0
- package/dist/api/routing/middleware/dynamic-middleware.d.ts.map +1 -0
- package/dist/api/routing/middleware/dynamic-middleware.js +39 -0
- package/dist/api/routing/middleware/generic-middleware.d.ts +9 -0
- package/dist/api/routing/middleware/generic-middleware.d.ts.map +1 -0
- package/dist/api/routing/middleware/generic-middleware.js +20 -0
- package/dist/api/routing/middleware/middleware.d.ts +28 -0
- package/dist/api/routing/middleware/middleware.d.ts.map +1 -0
- package/dist/api/routing/middleware/middleware.js +101 -0
- package/dist/api/routing/middleware.d.ts +6 -0
- package/dist/api/routing/middleware.d.ts.map +1 -0
- package/dist/api/routing/middleware.js +8 -0
- package/dist/api/routing.d.ts +18 -28
- package/dist/api/routing.d.ts.map +1 -1
- package/dist/api/routing.js +3 -3
- package/package.json +27 -7
- package/src/api/layerUtils.ts +33 -0
- package/src/api/routing/middleware/ContextProvider.ts +136 -0
- package/src/api/routing/middleware/DynamicMiddleware.ts +317 -0
- package/src/api/routing/{dynamic-middleware.ts → middleware/dynamic-middleware.ts} +29 -63
- package/src/api/routing/middleware/generic-middleware.ts +38 -0
- package/src/api/routing/middleware/middleware.ts +134 -0
- package/src/api/routing/middleware.ts +7 -0
- package/src/api/routing.ts +37 -56
- package/test/controller.test.ts +132 -15
- package/test/dist/controller.test.d.ts.map +1 -1
- package/dist/api/routing/DynamicMiddleware.d.ts +0 -104
- package/dist/api/routing/DynamicMiddleware.d.ts.map +0 -1
- package/dist/api/routing/DynamicMiddleware.js +0 -122
- package/dist/api/routing/dynamic-middleware.d.ts +0 -24
- package/dist/api/routing/dynamic-middleware.d.ts.map +0 -1
- package/dist/api/routing/dynamic-middleware.js +0 -39
- package/src/api/routing/DynamicMiddleware.ts +0 -527
package/src/api/routing.ts
CHANGED
|
@@ -4,35 +4,16 @@
|
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
5
|
import { determineMethod, isCommand } from "@effect-app/infra/api/routing/utils"
|
|
6
6
|
import { Rpc, RpcGroup, RpcServer } from "@effect/rpc"
|
|
7
|
-
import { type Array, Duration, Effect, Layer, type NonEmptyArray,
|
|
7
|
+
import { type Array, Duration, Effect, Layer, type NonEmptyArray, Predicate, Request, S, Schedule, Schema } from "effect-app"
|
|
8
8
|
import type { GetEffectContext, GetEffectError, RPCContextMap } from "effect-app/client/req"
|
|
9
9
|
import { type HttpHeaders, HttpRouter } from "effect-app/http"
|
|
10
10
|
import { typedKeysOf, typedValuesOf } from "effect-app/utils"
|
|
11
11
|
import type { Contravariant } from "effect/Types"
|
|
12
12
|
import { type YieldWrap } from "effect/Utils"
|
|
13
|
-
import {
|
|
13
|
+
import { type LayerUtils } from "./layerUtils.js"
|
|
14
|
+
import { DevMode, type Middleware } from "./routing/middleware.js"
|
|
14
15
|
|
|
15
|
-
export * from "./routing/
|
|
16
|
-
|
|
17
|
-
export namespace LayersUtils {
|
|
18
|
-
export type GetLayersSuccess<Layers extends ReadonlyArray<Layer.Layer.Any>> = Layers extends
|
|
19
|
-
NonEmptyReadonlyArray<Layer.Layer.Any> ? {
|
|
20
|
-
[k in keyof Layers]: Layer.Layer.Success<Layers[k]>
|
|
21
|
-
}[number]
|
|
22
|
-
: never
|
|
23
|
-
|
|
24
|
-
export type GetLayersContext<Layers extends ReadonlyArray<Layer.Layer.Any>> = Layers extends
|
|
25
|
-
NonEmptyReadonlyArray<Layer.Layer.Any> ? {
|
|
26
|
-
[k in keyof Layers]: Layer.Layer.Context<Layers[k]>
|
|
27
|
-
}[number]
|
|
28
|
-
: never
|
|
29
|
-
|
|
30
|
-
export type GetLayersError<Layers extends ReadonlyArray<Layer.Layer.Any>> = Layers extends
|
|
31
|
-
NonEmptyReadonlyArray<Layer.Layer.Any> ? {
|
|
32
|
-
[k in keyof Layers]: Layer.Layer.Error<Layers[k]>
|
|
33
|
-
}[number]
|
|
34
|
-
: never
|
|
35
|
-
}
|
|
16
|
+
export * from "./routing/middleware.js"
|
|
36
17
|
|
|
37
18
|
// retry just once on optimistic concurrency exceptions
|
|
38
19
|
const optimisticConcurrencySchedule = Schedule.once.pipe(
|
|
@@ -463,10 +444,10 @@ export const makeRouter = <
|
|
|
463
444
|
})) as unknown as Layer<
|
|
464
445
|
{ [K in keyof RequestModules]: Rpc.Handler<K> },
|
|
465
446
|
| Layer.Error<typeof middleware.Default>
|
|
466
|
-
|
|
|
447
|
+
| LayerUtils.GetLayersError<MakeDependencies>,
|
|
467
448
|
| RPCRouteR<typeof mapped[keyof typeof mapped]>
|
|
468
449
|
| Layer.Context<typeof middleware.Default>
|
|
469
|
-
|
|
|
450
|
+
| LayerUtils.GetLayersContext<MakeDependencies>
|
|
470
451
|
>
|
|
471
452
|
|
|
472
453
|
return RpcServer
|
|
@@ -492,12 +473,12 @@ export const makeRouter = <
|
|
|
492
473
|
)
|
|
493
474
|
) as (Layer.Layer<
|
|
494
475
|
Router,
|
|
495
|
-
|
|
|
476
|
+
| LayerUtils.GetLayersError<MakeDependencies>
|
|
496
477
|
| MakeE
|
|
497
478
|
| Layer.Error<typeof middleware.Default>,
|
|
498
|
-
|
|
|
479
|
+
| LayerUtils.GetLayersContext<MakeDependencies>
|
|
499
480
|
| Layer.Context<typeof middleware.Default>
|
|
500
|
-
| Exclude<MakeR,
|
|
481
|
+
| Exclude<MakeR, LayerUtils.GetLayersSuccess<MakeDependencies>>
|
|
501
482
|
>)
|
|
502
483
|
|
|
503
484
|
// Effect.Effect<HttpRouter.HttpRouter<unknown, HttpRouter.HttpRouter.DefaultServices>, never, UserRouter>
|
|
@@ -515,7 +496,7 @@ export const makeRouter = <
|
|
|
515
496
|
dependencies: Array<Layer.Layer.Any>
|
|
516
497
|
effect: (match: typeof router3) => Generator<
|
|
517
498
|
YieldWrap<
|
|
518
|
-
Effect<any, any, Make["strict"] extends false ? any :
|
|
499
|
+
Effect<any, any, Make["strict"] extends false ? any : LayerUtils.GetLayersSuccess<Make["dependencies"]>>
|
|
519
500
|
>,
|
|
520
501
|
{ [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> },
|
|
521
502
|
any
|
|
@@ -533,13 +514,13 @@ export const makeRouter = <
|
|
|
533
514
|
routes: Layer.Layer<
|
|
534
515
|
RouterShape<Resource>,
|
|
535
516
|
| MakeErrors<Make>
|
|
536
|
-
|
|
|
517
|
+
| LayerUtils.GetLayersError<Make["dependencies"]>
|
|
537
518
|
| Layer.Error<typeof middleware.Default>,
|
|
538
|
-
|
|
|
519
|
+
| LayerUtils.GetLayersContext<Make["dependencies"]>
|
|
539
520
|
| Layer.Context<typeof middleware.Default>
|
|
540
521
|
| Exclude<
|
|
541
522
|
MakeContext<Make>,
|
|
542
|
-
|
|
523
|
+
LayerUtils.GetLayersSuccess<Make["dependencies"]>
|
|
543
524
|
>
|
|
544
525
|
>
|
|
545
526
|
|
|
@@ -552,7 +533,7 @@ export const makeRouter = <
|
|
|
552
533
|
effect: Effect<
|
|
553
534
|
{ [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> },
|
|
554
535
|
any,
|
|
555
|
-
Make["strict"] extends false ? any :
|
|
536
|
+
Make["strict"] extends false ? any : LayerUtils.GetLayersSuccess<Make["dependencies"]>
|
|
556
537
|
>
|
|
557
538
|
strict?: boolean
|
|
558
539
|
/** @deprecated */
|
|
@@ -566,13 +547,13 @@ export const makeRouter = <
|
|
|
566
547
|
routes: Layer.Layer<
|
|
567
548
|
RouterShape<Resource>,
|
|
568
549
|
| MakeErrors<Make>
|
|
569
|
-
|
|
|
550
|
+
| LayerUtils.GetLayersError<Make["dependencies"]>
|
|
570
551
|
| Layer.Error<typeof middleware.Default>,
|
|
571
|
-
|
|
|
552
|
+
| LayerUtils.GetLayersContext<Make["dependencies"]>
|
|
572
553
|
| Layer.Context<typeof middleware.Default>
|
|
573
554
|
| Exclude<
|
|
574
555
|
MakeContext<Make>,
|
|
575
|
-
|
|
556
|
+
LayerUtils.GetLayersSuccess<Make["dependencies"]>
|
|
576
557
|
>
|
|
577
558
|
>
|
|
578
559
|
|
|
@@ -585,7 +566,7 @@ export const makeRouter = <
|
|
|
585
566
|
effect: Effect<
|
|
586
567
|
{ [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> },
|
|
587
568
|
any,
|
|
588
|
-
Make["strict"] extends false ? any :
|
|
569
|
+
Make["strict"] extends false ? any : LayerUtils.GetLayersSuccess<Make["dependencies"]>
|
|
589
570
|
>
|
|
590
571
|
strict?: boolean
|
|
591
572
|
/** @deprecated */
|
|
@@ -599,13 +580,13 @@ export const makeRouter = <
|
|
|
599
580
|
routes: Layer.Layer<
|
|
600
581
|
RouterShape<Resource>,
|
|
601
582
|
| MakeErrors<Make>
|
|
602
|
-
|
|
|
583
|
+
| LayerUtils.GetLayersError<Make["dependencies"]>
|
|
603
584
|
| Layer.Error<typeof middleware.Default>,
|
|
604
|
-
|
|
|
585
|
+
| LayerUtils.GetLayersContext<Make["dependencies"]>
|
|
605
586
|
| Layer.Context<typeof middleware.Default>
|
|
606
587
|
| Exclude<
|
|
607
588
|
MakeContext<Make>,
|
|
608
|
-
|
|
589
|
+
LayerUtils.GetLayersSuccess<Make["dependencies"]>
|
|
609
590
|
>
|
|
610
591
|
>
|
|
611
592
|
|
|
@@ -618,7 +599,7 @@ export const makeRouter = <
|
|
|
618
599
|
effect: Effect<
|
|
619
600
|
{ [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> },
|
|
620
601
|
any,
|
|
621
|
-
Make["strict"] extends false ? any :
|
|
602
|
+
Make["strict"] extends false ? any : LayerUtils.GetLayersSuccess<Make["dependencies"]>
|
|
622
603
|
>
|
|
623
604
|
strict?: boolean
|
|
624
605
|
/** @deprecated */
|
|
@@ -632,13 +613,13 @@ export const makeRouter = <
|
|
|
632
613
|
routes: Layer.Layer<
|
|
633
614
|
RouterShape<Resource>,
|
|
634
615
|
| MakeErrors<Make>
|
|
635
|
-
|
|
|
616
|
+
| LayerUtils.GetLayersError<Make["dependencies"]>
|
|
636
617
|
| Layer.Error<typeof middleware.Default>,
|
|
637
|
-
|
|
|
618
|
+
| LayerUtils.GetLayersContext<Make["dependencies"]>
|
|
638
619
|
| Layer.Context<typeof middleware.Default>
|
|
639
620
|
| Exclude<
|
|
640
621
|
MakeContext<Make>,
|
|
641
|
-
|
|
622
|
+
LayerUtils.GetLayersSuccess<Make["dependencies"]>
|
|
642
623
|
>
|
|
643
624
|
>
|
|
644
625
|
|
|
@@ -651,7 +632,7 @@ export const makeRouter = <
|
|
|
651
632
|
effect: Effect<
|
|
652
633
|
{ [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> },
|
|
653
634
|
any,
|
|
654
|
-
|
|
635
|
+
LayerUtils.GetLayersSuccess<Make["dependencies"]>
|
|
655
636
|
>
|
|
656
637
|
strict?: boolean
|
|
657
638
|
/** @deprecated */
|
|
@@ -665,13 +646,13 @@ export const makeRouter = <
|
|
|
665
646
|
routes: Layer.Layer<
|
|
666
647
|
RouterShape<Resource>,
|
|
667
648
|
| MakeErrors<Make>
|
|
668
|
-
|
|
|
649
|
+
| LayerUtils.GetLayersError<Make["dependencies"]>
|
|
669
650
|
| Layer.Error<typeof middleware.Default>,
|
|
670
|
-
|
|
|
651
|
+
| LayerUtils.GetLayersContext<Make["dependencies"]>
|
|
671
652
|
| Layer.Context<typeof middleware.Default>
|
|
672
653
|
| Exclude<
|
|
673
654
|
MakeContext<Make>,
|
|
674
|
-
|
|
655
|
+
LayerUtils.GetLayersSuccess<Make["dependencies"]>
|
|
675
656
|
>
|
|
676
657
|
>
|
|
677
658
|
|
|
@@ -684,7 +665,7 @@ export const makeRouter = <
|
|
|
684
665
|
effect: Effect<
|
|
685
666
|
{ [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> },
|
|
686
667
|
any,
|
|
687
|
-
|
|
668
|
+
LayerUtils.GetLayersSuccess<Make["dependencies"]>
|
|
688
669
|
>
|
|
689
670
|
strict?: boolean
|
|
690
671
|
}
|
|
@@ -696,13 +677,13 @@ export const makeRouter = <
|
|
|
696
677
|
routes: Layer.Layer<
|
|
697
678
|
RouterShape<Resource>,
|
|
698
679
|
| MakeErrors<Make>
|
|
699
|
-
|
|
|
680
|
+
| LayerUtils.GetLayersError<Make["dependencies"]>
|
|
700
681
|
| Layer.Error<typeof middleware.Default>,
|
|
701
|
-
|
|
|
682
|
+
| LayerUtils.GetLayersContext<Make["dependencies"]>
|
|
702
683
|
| Layer.Context<typeof middleware.Default>
|
|
703
684
|
| Exclude<
|
|
704
685
|
MakeContext<Make>,
|
|
705
|
-
|
|
686
|
+
LayerUtils.GetLayersSuccess<Make["dependencies"]>
|
|
706
687
|
>
|
|
707
688
|
>
|
|
708
689
|
|
|
@@ -714,7 +695,7 @@ export const makeRouter = <
|
|
|
714
695
|
dependencies: Array<Layer.Layer.Any>
|
|
715
696
|
effect: (match: typeof router3) => Generator<
|
|
716
697
|
YieldWrap<
|
|
717
|
-
Effect<any, any, Make["strict"] extends false ? any :
|
|
698
|
+
Effect<any, any, Make["strict"] extends false ? any : LayerUtils.GetLayersSuccess<Make["dependencies"]>>
|
|
718
699
|
>,
|
|
719
700
|
{ [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> },
|
|
720
701
|
any
|
|
@@ -730,13 +711,13 @@ export const makeRouter = <
|
|
|
730
711
|
routes: Layer.Layer<
|
|
731
712
|
RouterShape<Resource>,
|
|
732
713
|
| MakeErrors<Make>
|
|
733
|
-
|
|
|
714
|
+
| LayerUtils.GetLayersError<Make["dependencies"]>
|
|
734
715
|
| Layer.Error<typeof middleware.Default>,
|
|
735
|
-
|
|
|
716
|
+
| LayerUtils.GetLayersContext<Make["dependencies"]>
|
|
736
717
|
| Layer.Context<typeof middleware.Default>
|
|
737
718
|
| Exclude<
|
|
738
719
|
MakeContext<Make>,
|
|
739
|
-
|
|
720
|
+
LayerUtils.GetLayersSuccess<Make["dependencies"]>
|
|
740
721
|
>
|
|
741
722
|
>
|
|
742
723
|
|
package/test/controller.test.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
3
|
-
import { type MakeContext, type MakeErrors, makeRouter
|
|
3
|
+
import { type MakeContext, type MakeErrors, makeRouter } from "@effect-app/infra/api/routing"
|
|
4
4
|
import type { RequestContext } from "@effect-app/infra/RequestContext"
|
|
5
5
|
import { expect, expectTypeOf, it } from "@effect/vitest"
|
|
6
6
|
import { type Array, Context, Effect, Layer, Option, S } from "effect-app"
|
|
7
7
|
import { InvalidStateError, makeRpcClient, type RPCContextMap, UnauthorizedError } from "effect-app/client"
|
|
8
|
-
import { HttpServerRequest } from "effect-app/http"
|
|
8
|
+
import { type HttpHeaders, type HttpRouter, HttpServerRequest } from "effect-app/http"
|
|
9
9
|
import { Class, TaggedError } from "effect-app/Schema"
|
|
10
|
-
import { ContextProvider, makeMiddleware, mergeContextProviders, MergedContextProvider } from "../src/api/routing/
|
|
10
|
+
import { ContextProvider, DefaultGenericMiddlewares, implementMiddleware, makeMiddleware, mergeContextProviders, MergedContextProvider } from "../src/api/routing/middleware.js"
|
|
11
11
|
import { sort } from "../src/api/routing/tsort.js"
|
|
12
12
|
import { SomeService } from "./query.test.js"
|
|
13
13
|
|
|
@@ -76,11 +76,24 @@ class MyContextProvider extends Effect.Service<MyContextProvider>()("MyContextPr
|
|
|
76
76
|
})
|
|
77
77
|
}) {}
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
// @effect-diagnostics-next-line missingEffectServiceDependency:off
|
|
80
|
+
class MyContextProvider2 extends Effect.Service<MyContextProvider2>()("MyContextProvider2", {
|
|
80
81
|
effect: Effect.gen(function*() {
|
|
82
|
+
yield* SomeService
|
|
83
|
+
if (Math.random() > 0.5) return yield* new CustomError1()
|
|
84
|
+
|
|
81
85
|
return Effect.gen(function*() {
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
// the only requiremeno you can have are the one provided by HttpRouter.HttpRouter.Provided
|
|
87
|
+
yield* HttpServerRequest.HttpServerRequest
|
|
88
|
+
|
|
89
|
+
// this is allowed here but mergeContextProviders/MergedContextProvider will trigger an error
|
|
90
|
+
// yield* SomeElse
|
|
91
|
+
|
|
92
|
+
// currently the effectful context provider cannot trigger an error when building the per request context
|
|
93
|
+
// this is allowed here but mergeContextProviders/MergedContextProvider will trigger an error
|
|
94
|
+
// if (Math.random() > 0.5) return yield* new CustomError2()
|
|
95
|
+
|
|
96
|
+
return Context.make(SomeElse, new SomeElse({ b: 2 }))
|
|
84
97
|
})
|
|
85
98
|
})
|
|
86
99
|
}) {}
|
|
@@ -90,9 +103,9 @@ export const contextProvider2 = ContextProvider(merged)
|
|
|
90
103
|
export const contextProvider3 = MergedContextProvider(MyContextProvider)
|
|
91
104
|
expectTypeOf(contextProvider2).toEqualTypeOf<typeof someContextProvider>()
|
|
92
105
|
expectTypeOf(contextProvider3).toEqualTypeOf<typeof contextProvider2>()
|
|
93
|
-
const merged2 = mergeContextProviders(MyContextProvider,
|
|
106
|
+
const merged2 = mergeContextProviders(MyContextProvider, MyContextProvider2)
|
|
94
107
|
export const contextProvider22 = ContextProvider(merged2)
|
|
95
|
-
export const contextProvider23 = MergedContextProvider(MyContextProvider,
|
|
108
|
+
export const contextProvider23 = MergedContextProvider(MyContextProvider, MyContextProvider2)
|
|
96
109
|
expectTypeOf(contextProvider23).toEqualTypeOf<typeof contextProvider22>()
|
|
97
110
|
|
|
98
111
|
export type RequestContextMap = {
|
|
@@ -124,8 +137,10 @@ class AllowAnonymous extends Effect.Service<AllowAnonymous>()("AllowAnonymous",
|
|
|
124
137
|
})
|
|
125
138
|
}) {}
|
|
126
139
|
|
|
140
|
+
// @effect-diagnostics-next-line missingEffectServiceDependency:off
|
|
127
141
|
class RequireRoles extends Effect.Service<RequireRoles>()("RequireRoles", {
|
|
128
142
|
effect: Effect.gen(function*() {
|
|
143
|
+
yield* Some
|
|
129
144
|
return {
|
|
130
145
|
handle: Effect.fn(
|
|
131
146
|
function*(cfg: { requireRoles?: readonly string[] }) {
|
|
@@ -154,19 +169,33 @@ class Test extends Effect.Service<Test>()("Test", {
|
|
|
154
169
|
})
|
|
155
170
|
}) {}
|
|
156
171
|
|
|
172
|
+
export class BogusMiddleware extends Effect.Service<BogusMiddleware>()("BogusMiddleware", {
|
|
173
|
+
effect: Effect.gen(function*() {
|
|
174
|
+
return <A, E>(
|
|
175
|
+
handle: (input: any, headers: HttpHeaders.Headers) => Effect.Effect<A, E, HttpRouter.HttpRouter.Provided>,
|
|
176
|
+
_moduleName: string
|
|
177
|
+
) =>
|
|
178
|
+
Effect.fnUntraced(function*(input: any, headers: HttpHeaders.Headers) {
|
|
179
|
+
return yield* handle(input, headers)
|
|
180
|
+
})
|
|
181
|
+
})
|
|
182
|
+
}) {}
|
|
183
|
+
|
|
184
|
+
const contextProvider = MergedContextProvider(MyContextProvider2, MyContextProvider)
|
|
157
185
|
// TODO: eventually it might be nice if we have total control over order somehow..
|
|
158
186
|
// [ AddRequestNameToSpanContext, RequestCacheContext, UninterruptibleMiddleware, Dynamic(or individual, AllowAnonymous, RequireRoles, Test - or whichever order) ]
|
|
159
187
|
const middleware = makeMiddleware<RequestContextMap>()({
|
|
160
|
-
dependencies: [Layer.effect(Str2, Str)],
|
|
161
188
|
// TODO: I guess it makes sense to support just passing array of context providers too, like dynamicMiddlewares?
|
|
162
|
-
contextProvider
|
|
189
|
+
contextProvider,
|
|
190
|
+
genericMiddlewares: [...DefaultGenericMiddlewares, BogusMiddleware],
|
|
163
191
|
// or is the better api to use constructors outside, like how contextProvider is used now?
|
|
164
192
|
dynamicMiddlewares: {
|
|
165
193
|
requireRoles: RequireRoles,
|
|
166
194
|
allowAnonymous: AllowAnonymous,
|
|
167
195
|
test: Test
|
|
168
196
|
},
|
|
169
|
-
// TODO: 0..n of these generic middlewares?
|
|
197
|
+
// // TODO: 0..n of these generic middlewares?
|
|
198
|
+
dependencies: [Layer.effect(Str2, Str)],
|
|
170
199
|
execute: (maker) =>
|
|
171
200
|
Effect.gen(function*() {
|
|
172
201
|
return maker(
|
|
@@ -182,15 +211,23 @@ const middleware = makeMiddleware<RequestContextMap>()({
|
|
|
182
211
|
yield* HttpServerRequest.HttpServerRequest // provided by HttpRouter.HttpRouter.Provided
|
|
183
212
|
|
|
184
213
|
return yield* handler(req, headers)
|
|
185
|
-
.pipe(
|
|
186
|
-
// TODO: make this depend on query/command, and consider if middleware also should be affected. right now it's not.
|
|
187
|
-
Effect.uninterruptible
|
|
188
|
-
)
|
|
189
214
|
})
|
|
190
215
|
)
|
|
191
216
|
})
|
|
192
217
|
})
|
|
193
218
|
|
|
219
|
+
const middleware2 = makeMiddleware<RequestContextMap>()({
|
|
220
|
+
// TODO: I guess it makes sense to support just passing array of context providers too, like dynamicMiddlewares?
|
|
221
|
+
contextProvider,
|
|
222
|
+
genericMiddlewares: [...DefaultGenericMiddlewares, BogusMiddleware],
|
|
223
|
+
// or is the better api to use constructors outside, like how contextProvider is used now?
|
|
224
|
+
dynamicMiddlewares: {
|
|
225
|
+
requireRoles: RequireRoles,
|
|
226
|
+
allowAnonymous: AllowAnonymous,
|
|
227
|
+
test: Test
|
|
228
|
+
}
|
|
229
|
+
})
|
|
230
|
+
|
|
194
231
|
export type RequestConfig = {
|
|
195
232
|
/** Disable authentication requirement */
|
|
196
233
|
allowAnonymous?: true
|
|
@@ -266,6 +303,8 @@ export class SomethingService2 extends Effect.Service<SomethingService2>()("Some
|
|
|
266
303
|
|
|
267
304
|
export const { Router, matchAll, matchFor } = makeRouter(middleware, true)
|
|
268
305
|
|
|
306
|
+
export const r2 = makeRouter(middleware2, true)
|
|
307
|
+
|
|
269
308
|
const router = Router(Something)({
|
|
270
309
|
dependencies: [
|
|
271
310
|
SomethingRepo.Default,
|
|
@@ -344,3 +383,81 @@ expectTypeOf({} as MakeErrors<typeof router.make>).toEqualTypeOf<InvalidStateErr
|
|
|
344
383
|
expectTypeOf({} as makeContext).toEqualTypeOf<
|
|
345
384
|
SomethingService | SomethingRepo | SomethingService2
|
|
346
385
|
>()
|
|
386
|
+
|
|
387
|
+
const router2 = r2.Router(Something)({
|
|
388
|
+
dependencies: [
|
|
389
|
+
SomethingRepo.Default,
|
|
390
|
+
SomethingService.Default,
|
|
391
|
+
SomethingService2.Default
|
|
392
|
+
],
|
|
393
|
+
*effect(match) {
|
|
394
|
+
const repo = yield* SomethingRepo
|
|
395
|
+
const smth = yield* SomethingService
|
|
396
|
+
const smth2 = yield* SomethingService2
|
|
397
|
+
|
|
398
|
+
// this gets catched in 'routes' type
|
|
399
|
+
if (Math.random() > 0.5) {
|
|
400
|
+
return yield* new InvalidStateError("ciao")
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
console.log({ repo, smth, smth2 })
|
|
404
|
+
|
|
405
|
+
return match({
|
|
406
|
+
Eff: () =>
|
|
407
|
+
Effect
|
|
408
|
+
.gen(function*() {
|
|
409
|
+
const some = yield* Some
|
|
410
|
+
return yield* Effect.logInfo("Some", some)
|
|
411
|
+
}),
|
|
412
|
+
|
|
413
|
+
*Gen() {
|
|
414
|
+
const some = yield* Some
|
|
415
|
+
return yield* Effect.logInfo("Some", some)
|
|
416
|
+
},
|
|
417
|
+
*GetSomething(req) {
|
|
418
|
+
console.log(req.id)
|
|
419
|
+
|
|
420
|
+
const _b = yield* Effect.succeed(false)
|
|
421
|
+
if (_b) {
|
|
422
|
+
// expected errors here because RequestError is not a valid error for controllers
|
|
423
|
+
// yield* new RequestError(1 as any)
|
|
424
|
+
// return yield* new RequestError(1 as any)
|
|
425
|
+
}
|
|
426
|
+
if (Math.random() > 0.5) {
|
|
427
|
+
return yield* Effect.succeed("12")
|
|
428
|
+
}
|
|
429
|
+
if (!_b) {
|
|
430
|
+
return yield* new UnauthorizedError()
|
|
431
|
+
} else {
|
|
432
|
+
// expected an error here because a boolean is not a string
|
|
433
|
+
// return _b
|
|
434
|
+
return "12"
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
DoSomething: {
|
|
438
|
+
*raw() {
|
|
439
|
+
return yield* Effect.succeed(undefined)
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
GetSomething2: {
|
|
443
|
+
raw: Some.use(() => Effect.succeed("12"))
|
|
444
|
+
}
|
|
445
|
+
})
|
|
446
|
+
}
|
|
447
|
+
})
|
|
448
|
+
|
|
449
|
+
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
450
|
+
const matched2 = matchAll({ router: router2 })
|
|
451
|
+
expectTypeOf({} as Layer.Context<typeof matched2>).toEqualTypeOf<SomeService>()
|
|
452
|
+
|
|
453
|
+
type makeContext2 = MakeContext<typeof router2.make>
|
|
454
|
+
expectTypeOf({} as MakeErrors<typeof router2.make>).toEqualTypeOf<InvalidStateError>()
|
|
455
|
+
expectTypeOf({} as makeContext2).toEqualTypeOf<
|
|
456
|
+
SomethingService | SomethingRepo | SomethingService2
|
|
457
|
+
>()
|
|
458
|
+
|
|
459
|
+
export const dynamicMiddlewares = implementMiddleware<RequestContextMap>()({
|
|
460
|
+
requireRoles: RequireRoles,
|
|
461
|
+
allowAnonymous: AllowAnonymous,
|
|
462
|
+
test: Test
|
|
463
|
+
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.test.d.ts","sourceRoot":"","sources":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, Effect, Layer, type NonEmptyArray, type Request, type S, type Scope } from "effect-app";
|
|
2
|
-
import type { GetEffectContext, RPCContextMap } from "effect-app/client/req";
|
|
3
|
-
import { HttpHeaders, type HttpRouter, HttpServerRequest } from "effect-app/http";
|
|
4
|
-
import type * as EffectRequest from "effect/Request";
|
|
5
|
-
import { type LayersUtils } from "../routing.js";
|
|
6
|
-
import { type AnyContextWithLayer } from "./dynamic-middleware.js";
|
|
7
|
-
type GetContext<T> = T extends Context.Context<infer Y> ? Y : never;
|
|
8
|
-
export type MakeRPCHandlerFactory<RequestContextMap extends Record<string, RPCContextMap.Any>, MiddlewareR> = <T extends {
|
|
9
|
-
config?: Partial<Record<keyof RequestContextMap, any>>;
|
|
10
|
-
}, Req extends S.TaggedRequest.All, HandlerR>(schema: T & S.Schema<Req, any, never>, handler: (request: Req, headers: any) => Effect.Effect<EffectRequest.Request.Success<Req>, EffectRequest.Request.Error<Req>, Exclude<HandlerR, GetEffectContext<RequestContextMap, (T & S.Schema<Req, any, never>)["config"]>>>, moduleName: string) => (req: Req, headers: any) => Effect.Effect<Request.Request.Success<Req>, Request.Request.Error<Req> | RequestContextMapErrors<RequestContextMap>, MiddlewareR | Exclude<HandlerR, GetEffectContext<RequestContextMap, (T & S.Schema<Req, any, never>)["config"]>>>;
|
|
11
|
-
export type RPCHandlerFactory<RequestContextMap extends Record<string, RPCContextMap.Any>, ContextProviderA> = <T extends {
|
|
12
|
-
config?: Partial<Record<keyof RequestContextMap, any>>;
|
|
13
|
-
}, Req extends S.TaggedRequest.All, HandlerR>(schema: T & S.Schema<Req, any, never>, handler: (request: Req, headers: any) => Effect.Effect<EffectRequest.Request.Success<Req>, EffectRequest.Request.Error<Req>, HandlerR>, moduleName: string) => (req: Req, headers: any) => Effect.Effect<Request.Request.Success<Req>, Request.Request.Error<Req> | RequestContextMapErrors<RequestContextMap>, HttpRouter.HttpRouter.Provided | Exclude<Exclude<HandlerR, GetEffectContext<RequestContextMap, (T & S.Schema<Req, any, never>)["config"]>>, ContextProviderA>>;
|
|
14
|
-
export type ContextProviderShape<ContextProviderA, ContextProviderR extends HttpRouter.HttpRouter.Provided> = Effect<Context.Context<ContextProviderA>, never, // no errors are allowed
|
|
15
|
-
ContextProviderR>;
|
|
16
|
-
export interface ContextProviderId {
|
|
17
|
-
_tag: "ContextProvider";
|
|
18
|
-
}
|
|
19
|
-
type RequestContextMapProvider<RequestContextMap extends Record<string, RPCContextMap.Any>> = {
|
|
20
|
-
[K in keyof RequestContextMap]: AnyContextWithLayer<{
|
|
21
|
-
[K in keyof RequestContextMap]?: RequestContextMap[K]["contextActivation"];
|
|
22
|
-
}, RequestContextMap[K]["service"], S.Schema.Type<RequestContextMap[K]["error"]>>;
|
|
23
|
-
};
|
|
24
|
-
export interface MiddlewareMake<RequestContextMap extends Record<string, RPCContextMap.Any>, // what services will the middleware provide dynamically to the handler, or raise errors.
|
|
25
|
-
MakeMiddlewareE, // what the middleware construction can fail with
|
|
26
|
-
MakeMiddlewareR, // what the middleware requires to be constructed
|
|
27
|
-
MiddlewareDependencies extends NonEmptyArray<Layer.Layer.Any>, // layers provided for the middleware to be constructed
|
|
28
|
-
ContextProviderA, // what the context provider provides
|
|
29
|
-
ContextProviderR extends HttpRouter.HttpRouter.Provided, // what the context provider requires
|
|
30
|
-
MakeContextProviderE, // what the context provider construction can fail with
|
|
31
|
-
MakeContextProviderR, // what the context provider construction requires
|
|
32
|
-
TI extends RequestContextMapProvider<RequestContextMap>> {
|
|
33
|
-
dependencies?: MiddlewareDependencies;
|
|
34
|
-
dynamicMiddlewares: TI;
|
|
35
|
-
contextProvider: Context.Tag<ContextProviderId, ContextProviderShape<ContextProviderA, ContextProviderR>> & {
|
|
36
|
-
Default: Layer.Layer<ContextProviderId, MakeContextProviderE, MakeContextProviderR>;
|
|
37
|
-
};
|
|
38
|
-
execute: (maker: (cb: MakeRPCHandlerFactory<RequestContextMap, ContextProviderA | HttpRouter.HttpRouter.Provided>) => MakeRPCHandlerFactory<RequestContextMap, ContextProviderA | HttpRouter.HttpRouter.Provided>) => Effect<MakeRPCHandlerFactory<RequestContextMap, ContextProviderA | HttpRouter.HttpRouter.Provided>, MakeMiddlewareE, MakeMiddlewareR | Scope>;
|
|
39
|
-
}
|
|
40
|
-
export declare const mergeContextProviders: <TDeps extends Array.NonEmptyReadonlyArray<(Context.Tag<any, Effect<Context.Context<any>, never, any> & {
|
|
41
|
-
_tag: any;
|
|
42
|
-
}> | Context.Tag<any, Effect<Context.Context<any>, never, never> & {
|
|
43
|
-
_tag: any;
|
|
44
|
-
}>) & {
|
|
45
|
-
new (...args: any[]): any;
|
|
46
|
-
Default: Layer.Layer<Effect<Context.Context<any>> & {
|
|
47
|
-
_tag: any;
|
|
48
|
-
}, any, any>;
|
|
49
|
-
}>>(...deps: { [K in keyof TDeps]: TDeps[K]["Service"] extends Effect<Context.Context<any>, never, HttpRouter.HttpRouter.Provided> ? TDeps[K] : `HttpRouter.HttpRouter.Provided are the only requirements ${TDeps[K]["Service"]["_tag"]}'s returned effect can have`; }) => {
|
|
50
|
-
dependencies: { [K in keyof TDeps]: TDeps[K]["Default"]; };
|
|
51
|
-
effect: Effect.Effect<Effect.Effect<Context.Context<GetContext<Effect.Success<InstanceType<TDeps[number]>>>>, never, Effect.Context<InstanceType<TDeps[number]>>>, LayersUtils.GetLayersError<{ [K in keyof TDeps]: TDeps[K]["Default"]; }>, LayersUtils.GetLayersSuccess<{ [K in keyof TDeps]: TDeps[K]["Default"]; }>>;
|
|
52
|
-
};
|
|
53
|
-
export interface MiddlewareMakerId {
|
|
54
|
-
_tag: "MiddlewareMaker";
|
|
55
|
-
}
|
|
56
|
-
export declare const ContextProvider: <ContextProviderA, MakeContextProviderE, MakeContextProviderR, ContextProviderR extends HttpRouter.HttpRouter.Provided, Dependencies extends NonEmptyArray<Layer.Layer.Any>>(input: {
|
|
57
|
-
effect: Effect<Effect<ContextProviderA, never, ContextProviderR>, MakeContextProviderE, MakeContextProviderR | Scope>;
|
|
58
|
-
dependencies?: Dependencies;
|
|
59
|
-
}) => Context.Tag<ContextProviderId, Effect<ContextProviderA, never, ContextProviderR>> & {
|
|
60
|
-
Default: Layer.Layer<ContextProviderId, MakeContextProviderE | LayersUtils.GetLayersError<Dependencies>, Exclude<MakeContextProviderR, LayersUtils.GetLayersSuccess<Dependencies>> | LayersUtils.GetLayersContext<Dependencies>>;
|
|
61
|
-
};
|
|
62
|
-
export declare const MergedContextProvider: <TDeps extends Array.NonEmptyReadonlyArray<(Context.Tag<any, Effect<Context.Context<any>, never, any> & {
|
|
63
|
-
_tag: any;
|
|
64
|
-
}> | Context.Tag<any, Effect<Context.Context<any>, never, never> & {
|
|
65
|
-
_tag: any;
|
|
66
|
-
}>) & {
|
|
67
|
-
new (...args: any[]): any;
|
|
68
|
-
Default: Layer.Layer<Effect<Context.Context<any>> & {
|
|
69
|
-
_tag: any;
|
|
70
|
-
}, any, any>;
|
|
71
|
-
}>>(...deps: { [K in keyof TDeps]: TDeps[K]["Service"] extends Effect<Context.Context<any>, never, HttpRouter.HttpRouter.Provided> ? TDeps[K] : `HttpRouter.HttpRouter.Provided are the only requirements ${TDeps[K]["Service"]["_tag"]}'s returned effect can have`; }) => Context.Tag<ContextProviderId, Effect.Effect<Context.Context<GetContext<Effect.Success<InstanceType<TDeps[number]>>>>, never, Effect.Context<InstanceType<TDeps[number]>>>> & {
|
|
72
|
-
Default: Layer.Layer<ContextProviderId, LayersUtils.GetLayersError<{ [K in keyof TDeps]: TDeps[K]["Default"]; }>, Exclude<InstanceType<TDeps[number]>, LayersUtils.GetLayersSuccess<{ [K in keyof TDeps]: TDeps[K]["Default"]; }>> | LayersUtils.GetLayersContext<{ [K in keyof TDeps]: TDeps[K]["Default"]; }>>;
|
|
73
|
-
};
|
|
74
|
-
export declare const EmptyContextProvider: Context.Tag<ContextProviderId, Effect<Context.Context<never>, never, never>> & {
|
|
75
|
-
Default: Layer.Layer<ContextProviderId, never, never>;
|
|
76
|
-
};
|
|
77
|
-
export type Middleware<RequestContextMap extends Record<string, RPCContextMap.Any>, // what services will the middlware provide dynamically to the handler, or raise errors.
|
|
78
|
-
MakeMiddlewareE, // what the middleware construction can fail with
|
|
79
|
-
MakeMiddlewareR, // what the middlware requires to be constructed
|
|
80
|
-
ContextProviderA> = Context.Tag<MiddlewareMakerId, MiddlewareMakerId & {
|
|
81
|
-
effect: RPCHandlerFactory<RequestContextMap, ContextProviderA>;
|
|
82
|
-
}> & {
|
|
83
|
-
Default: Layer.Layer<MiddlewareMakerId, MakeMiddlewareE, MakeMiddlewareR>;
|
|
84
|
-
};
|
|
85
|
-
export type RequestContextMapErrors<RequestContextMap extends Record<string, RPCContextMap.Any>> = S.Schema.Type<RequestContextMap[keyof RequestContextMap]["error"]>;
|
|
86
|
-
declare const DevMode_base: Context.ReferenceClass<DevMode, "DevMode", boolean>;
|
|
87
|
-
export declare class DevMode extends DevMode_base {
|
|
88
|
-
}
|
|
89
|
-
export declare const requestMiddleware: <A, E, R>(handle: (input: any, headers: HttpHeaders.Headers) => Effect.Effect<A, E, R>, moduleName: string) => (input: any, rpcHeaders: HttpHeaders.Headers) => Effect.Effect<A, E, HttpServerRequest.HttpServerRequest | R>;
|
|
90
|
-
export declare const makeMiddleware: <RequestContextMap extends Record<string, RPCContextMap.Any>>() => <MakeMiddlewareE, // what the middleware construction can fail with
|
|
91
|
-
MakeMiddlewareR, // what the middlware requires to be constructed
|
|
92
|
-
MiddlewareDependencies extends NonEmptyArray<Layer.Layer.Any>, // layers provided for the middlware to be constructed
|
|
93
|
-
ContextProviderA, // what the context provider provides
|
|
94
|
-
ContextProviderR extends HttpRouter.HttpRouter.Provided, // what the context provider requires
|
|
95
|
-
MakeContextProviderE, // what the context provider construction can fail with
|
|
96
|
-
MakeContextProviderR, // what the context provider construction requires
|
|
97
|
-
TI extends RequestContextMapProvider<RequestContextMap>>(make: MiddlewareMake<RequestContextMap, MakeMiddlewareE, MakeMiddlewareR, MiddlewareDependencies, ContextProviderA, ContextProviderR, MakeContextProviderE, MakeContextProviderR, TI>) => Context.Tag<MiddlewareMakerId, {
|
|
98
|
-
effect: RPCHandlerFactory<RequestContextMap, ContextProviderA>;
|
|
99
|
-
_tag: "MiddlewareMaker";
|
|
100
|
-
}> & {
|
|
101
|
-
Default: Layer.Layer<MiddlewareMakerId, MakeMiddlewareE | MakeContextProviderE, MakeContextProviderR | LayersUtils.GetLayersContext<MiddlewareDependencies> | Exclude<MakeMiddlewareR, LayersUtils.GetLayersSuccess<MiddlewareDependencies>>>;
|
|
102
|
-
};
|
|
103
|
-
export {};
|
|
104
|
-
//# sourceMappingURL=DynamicMiddleware.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicMiddleware.d.ts","sourceRoot":"","sources":["../../../src/api/routing/DynamicMiddleware.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAS,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,aAAa,EAAqB,KAAK,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,EAAE,MAAM,YAAY,CAAA;AAC1I,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAC5E,OAAO,EAAE,WAAW,EAAE,KAAK,UAAU,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAGjF,OAAO,KAAK,KAAK,aAAa,MAAM,gBAAgB,CAAA;AAGpD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,KAAK,mBAAmB,EAAsC,MAAM,yBAAyB,CAAA;AAItG,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAInE,MAAM,MAAM,qBAAqB,CAC/B,iBAAiB,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,EAC3D,WAAW,IACT,CACF,CA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