@effect-app/infra 4.0.0-beta.21 → 4.0.0-beta.210
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 +1548 -0
- package/_check.sh +1 -1
- package/dist/CUPS.d.ts +7 -7
- package/dist/CUPS.d.ts.map +1 -1
- package/dist/CUPS.js +10 -12
- package/dist/Emailer/Sendgrid.d.ts +14 -14
- package/dist/Emailer/Sendgrid.d.ts.map +1 -1
- package/dist/Emailer/Sendgrid.js +16 -15
- package/dist/Emailer/fake.d.ts +1 -1
- package/dist/Emailer/service.d.ts +10 -4
- package/dist/Emailer/service.d.ts.map +1 -1
- package/dist/Emailer/service.js +3 -3
- package/dist/Emailer.d.ts +1 -1
- package/dist/MainFiberSet.d.ts +9 -9
- package/dist/MainFiberSet.d.ts.map +1 -1
- package/dist/MainFiberSet.js +3 -3
- package/dist/Model/Repository/Registry.d.ts +20 -0
- package/dist/Model/Repository/Registry.d.ts.map +1 -0
- package/dist/Model/Repository/Registry.js +17 -0
- package/dist/Model/Repository/ext.d.ts +33 -15
- package/dist/Model/Repository/ext.d.ts.map +1 -1
- package/dist/Model/Repository/ext.js +54 -2
- package/dist/Model/Repository/internal/internal.d.ts +6 -6
- package/dist/Model/Repository/internal/internal.d.ts.map +1 -1
- package/dist/Model/Repository/internal/internal.js +59 -41
- package/dist/Model/Repository/legacy.d.ts +1 -1
- package/dist/Model/Repository/makeRepo.d.ts +7 -6
- package/dist/Model/Repository/makeRepo.d.ts.map +1 -1
- package/dist/Model/Repository/makeRepo.js +5 -1
- package/dist/Model/Repository/service.d.ts +28 -23
- package/dist/Model/Repository/service.d.ts.map +1 -1
- package/dist/Model/Repository/validation.d.ts +46 -17
- package/dist/Model/Repository/validation.d.ts.map +1 -1
- package/dist/Model/Repository/validation.js +5 -5
- package/dist/Model/Repository.d.ts +2 -1
- package/dist/Model/Repository.d.ts.map +1 -1
- package/dist/Model/Repository.js +2 -1
- package/dist/Model/dsl.d.ts +4 -4
- package/dist/Model/dsl.d.ts.map +1 -1
- package/dist/Model/filter/filterApi.d.ts +5 -5
- package/dist/Model/filter/filterApi.d.ts.map +1 -1
- package/dist/Model/filter/types/errors.d.ts +1 -1
- package/dist/Model/filter/types/fields.d.ts +1 -1
- package/dist/Model/filter/types/path/common.d.ts +1 -1
- package/dist/Model/filter/types/path/eager.d.ts +1 -1
- package/dist/Model/filter/types/path/eager.d.ts.map +1 -1
- package/dist/Model/filter/types/path/eager.js +1 -1
- package/dist/Model/filter/types/path/index.d.ts +1 -1
- package/dist/Model/filter/types/utils.d.ts +1 -1
- package/dist/Model/filter/types/validator.d.ts +1 -1
- package/dist/Model/filter/types.d.ts +1 -1
- package/dist/Model/query/dsl.d.ts +16 -16
- package/dist/Model/query/dsl.d.ts.map +1 -1
- package/dist/Model/query/new-kid-interpreter.d.ts +6 -6
- package/dist/Model/query/new-kid-interpreter.d.ts.map +1 -1
- package/dist/Model/query/new-kid-interpreter.js +3 -3
- package/dist/Model/query.d.ts +1 -1
- package/dist/Model.d.ts +2 -1
- package/dist/Model.d.ts.map +1 -1
- package/dist/Model.js +2 -1
- package/dist/QueueMaker/SQLQueue.d.ts +5 -7
- package/dist/QueueMaker/SQLQueue.d.ts.map +1 -1
- package/dist/QueueMaker/SQLQueue.js +130 -116
- package/dist/QueueMaker/errors.d.ts +2 -2
- package/dist/QueueMaker/errors.d.ts.map +1 -1
- package/dist/QueueMaker/memQueue.d.ts +7 -4
- package/dist/QueueMaker/memQueue.d.ts.map +1 -1
- package/dist/QueueMaker/memQueue.js +75 -63
- package/dist/QueueMaker/sbqueue.d.ts +6 -3
- package/dist/QueueMaker/sbqueue.d.ts.map +1 -1
- package/dist/QueueMaker/sbqueue.js +52 -53
- package/dist/QueueMaker/service.d.ts +1 -1
- package/dist/RequestContext.d.ts +74 -35
- package/dist/RequestContext.d.ts.map +1 -1
- package/dist/RequestContext.js +13 -14
- package/dist/RequestFiberSet.d.ts +7 -7
- package/dist/RequestFiberSet.d.ts.map +1 -1
- package/dist/RequestFiberSet.js +3 -3
- package/dist/Store/ContextMapContainer.d.ts +19 -3
- package/dist/Store/ContextMapContainer.d.ts.map +1 -1
- package/dist/Store/ContextMapContainer.js +13 -3
- package/dist/Store/Cosmos/query.d.ts +1 -1
- package/dist/Store/Cosmos/query.d.ts.map +1 -1
- package/dist/Store/Cosmos/query.js +10 -12
- package/dist/Store/Cosmos.d.ts +1 -1
- package/dist/Store/Cosmos.d.ts.map +1 -1
- package/dist/Store/Cosmos.js +335 -243
- package/dist/Store/Disk.d.ts +2 -2
- package/dist/Store/Disk.d.ts.map +1 -1
- package/dist/Store/Disk.js +72 -35
- package/dist/Store/Memory.d.ts +6 -4
- package/dist/Store/Memory.d.ts.map +1 -1
- package/dist/Store/Memory.js +90 -57
- package/dist/Store/SQL/Pg.d.ts +4 -0
- package/dist/Store/SQL/Pg.d.ts.map +1 -0
- package/dist/Store/SQL/Pg.js +231 -0
- package/dist/Store/SQL/query.d.ts +38 -0
- package/dist/Store/SQL/query.d.ts.map +1 -0
- package/dist/Store/SQL/query.js +367 -0
- package/dist/Store/SQL.d.ts +20 -0
- package/dist/Store/SQL.d.ts.map +1 -0
- package/dist/Store/SQL.js +464 -0
- package/dist/Store/codeFilter.d.ts +1 -1
- package/dist/Store/codeFilter.d.ts.map +1 -1
- package/dist/Store/codeFilter.js +4 -2
- package/dist/Store/index.d.ts +5 -2
- package/dist/Store/index.d.ts.map +1 -1
- package/dist/Store/index.js +15 -3
- package/dist/Store/service.d.ts +18 -7
- package/dist/Store/service.d.ts.map +1 -1
- package/dist/Store/service.js +24 -6
- package/dist/Store/utils.d.ts +1 -1
- package/dist/Store/utils.d.ts.map +1 -1
- package/dist/Store/utils.js +3 -4
- package/dist/Store.d.ts +1 -1
- package/dist/adapters/SQL/Model.d.ts +31 -42
- package/dist/adapters/SQL/Model.d.ts.map +1 -1
- package/dist/adapters/SQL/Model.js +29 -38
- package/dist/adapters/SQL.d.ts +1 -1
- package/dist/adapters/ServiceBus.d.ts +11 -11
- package/dist/adapters/ServiceBus.d.ts.map +1 -1
- package/dist/adapters/ServiceBus.js +13 -15
- package/dist/adapters/cosmos-client.d.ts +3 -3
- package/dist/adapters/cosmos-client.d.ts.map +1 -1
- package/dist/adapters/cosmos-client.js +3 -3
- package/dist/adapters/index.d.ts +8 -2
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +8 -2
- package/dist/adapters/logger.d.ts +2 -2
- package/dist/adapters/logger.d.ts.map +1 -1
- package/dist/adapters/memQueue.d.ts +3 -3
- package/dist/adapters/memQueue.d.ts.map +1 -1
- package/dist/adapters/memQueue.js +3 -3
- package/dist/adapters/mongo-client.d.ts +3 -3
- package/dist/adapters/mongo-client.d.ts.map +1 -1
- package/dist/adapters/mongo-client.js +3 -3
- package/dist/adapters/redis-client.d.ts +3 -3
- package/dist/adapters/redis-client.d.ts.map +1 -1
- package/dist/adapters/redis-client.js +3 -3
- package/dist/api/ContextProvider.d.ts +8 -8
- package/dist/api/ContextProvider.d.ts.map +1 -1
- package/dist/api/ContextProvider.js +6 -6
- package/dist/api/codec.d.ts +1 -1
- package/dist/api/internal/RequestContextMiddleware.d.ts +2 -2
- package/dist/api/internal/RequestContextMiddleware.d.ts.map +1 -1
- package/dist/api/internal/RequestContextMiddleware.js +2 -2
- package/dist/api/internal/auth.d.ts +44 -6
- package/dist/api/internal/auth.d.ts.map +1 -1
- package/dist/api/internal/auth.js +160 -29
- package/dist/api/internal/events.d.ts +3 -3
- package/dist/api/internal/events.d.ts.map +1 -1
- package/dist/api/internal/events.js +10 -8
- package/dist/api/internal/health.d.ts +1 -1
- package/dist/api/layerUtils.d.ts +6 -6
- package/dist/api/layerUtils.d.ts.map +1 -1
- package/dist/api/layerUtils.js +5 -5
- package/dist/api/middlewares.d.ts +1 -1
- package/dist/api/reportError.d.ts +1 -1
- package/dist/api/routing/middleware/RouterMiddleware.d.ts +4 -4
- package/dist/api/routing/middleware/RouterMiddleware.d.ts.map +1 -1
- package/dist/api/routing/middleware/middleware.d.ts +39 -3
- package/dist/api/routing/middleware/middleware.d.ts.map +1 -1
- package/dist/api/routing/middleware/middleware.js +48 -16
- package/dist/api/routing/middleware.d.ts +1 -2
- package/dist/api/routing/middleware.d.ts.map +1 -1
- package/dist/api/routing/middleware.js +1 -2
- package/dist/api/routing/schema/jwt.d.ts +1 -1
- package/dist/api/routing/schema/jwt.d.ts.map +1 -1
- package/dist/api/routing/tsort.d.ts +1 -1
- package/dist/api/routing/tsort.d.ts.map +1 -1
- package/dist/api/routing/utils.d.ts +3 -3
- package/dist/api/routing/utils.d.ts.map +1 -1
- package/dist/api/routing.d.ts +80 -37
- package/dist/api/routing.d.ts.map +1 -1
- package/dist/api/routing.js +112 -40
- package/dist/api/setupRequest.d.ts +8 -5
- package/dist/api/setupRequest.d.ts.map +1 -1
- package/dist/api/setupRequest.js +12 -7
- package/dist/api/util.d.ts +1 -1
- package/dist/arbs.d.ts +1 -1
- package/dist/arbs.d.ts.map +1 -1
- package/dist/arbs.js +5 -3
- package/dist/errorReporter.d.ts +4 -4
- package/dist/errorReporter.d.ts.map +1 -1
- package/dist/errorReporter.js +20 -25
- package/dist/errors.d.ts +1 -1
- package/dist/fileUtil.d.ts +1 -1
- package/dist/fileUtil.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/logger/jsonLogger.d.ts +1 -1
- package/dist/logger/logFmtLogger.d.ts +1 -1
- package/dist/logger/shared.d.ts +1 -1
- package/dist/logger/shared.js +2 -2
- package/dist/logger.d.ts +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/otel.d.ts +66 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/otel.js +56 -0
- package/dist/rateLimit.d.ts +9 -3
- package/dist/rateLimit.d.ts.map +1 -1
- package/dist/rateLimit.js +5 -11
- package/dist/test.d.ts +2 -2
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js +1 -1
- package/dist/vitest.d.ts +1 -1
- package/examples/query.ts +39 -35
- package/package.json +45 -37
- package/src/CUPS.ts +9 -11
- package/src/Emailer/Sendgrid.ts +17 -14
- package/src/Emailer/service.ts +9 -3
- package/src/MainFiberSet.ts +5 -6
- package/src/Model/Repository/Registry.ts +33 -0
- package/src/Model/Repository/ext.ts +96 -10
- package/src/Model/Repository/internal/internal.ts +159 -139
- package/src/Model/Repository/makeRepo.ts +12 -10
- package/src/Model/Repository/service.ts +31 -22
- package/src/Model/Repository/validation.ts +4 -4
- package/src/Model/Repository.ts +1 -0
- package/src/Model/dsl.ts +3 -3
- package/src/Model/filter/types/path/eager.ts +1 -2
- package/src/Model/query/dsl.ts +18 -18
- package/src/Model/query/new-kid-interpreter.ts +2 -2
- package/src/Model.ts +1 -0
- package/src/QueueMaker/SQLQueue.ts +144 -152
- package/src/QueueMaker/memQueue.ts +104 -103
- package/src/QueueMaker/sbqueue.ts +70 -86
- package/src/RequestContext.ts +14 -16
- package/src/RequestFiberSet.ts +2 -2
- package/src/Store/ContextMapContainer.ts +41 -2
- package/src/Store/Cosmos/query.ts +16 -20
- package/src/Store/Cosmos.ts +473 -348
- package/src/Store/Disk.ts +102 -65
- package/src/Store/Memory.ts +118 -83
- package/src/Store/SQL/Pg.ts +352 -0
- package/src/Store/SQL/query.ts +409 -0
- package/src/Store/SQL.ts +734 -0
- package/src/Store/codeFilter.ts +3 -1
- package/src/Store/index.ts +17 -2
- package/src/Store/service.ts +32 -8
- package/src/Store/utils.ts +23 -22
- package/src/adapters/SQL/Model.ts +41 -40
- package/src/adapters/ServiceBus.ts +112 -116
- package/src/adapters/cosmos-client.ts +2 -2
- package/src/adapters/index.ts +7 -0
- package/src/adapters/memQueue.ts +2 -2
- package/src/adapters/mongo-client.ts +2 -2
- package/src/adapters/redis-client.ts +2 -2
- package/src/api/ContextProvider.ts +12 -13
- package/src/api/internal/RequestContextMiddleware.ts +1 -1
- package/src/api/internal/auth.ts +246 -44
- package/src/api/internal/events.ts +13 -9
- package/src/api/layerUtils.ts +8 -8
- package/src/api/routing/middleware/RouterMiddleware.ts +4 -4
- package/src/api/routing/middleware/middleware.ts +55 -14
- package/src/api/routing/middleware.ts +0 -2
- package/src/api/routing.ts +298 -128
- package/src/api/setupRequest.ts +28 -8
- package/src/arbs.ts +4 -2
- package/src/errorReporter.ts +62 -74
- package/src/logger/shared.ts +1 -1
- package/src/otel.ts +141 -0
- package/src/rateLimit.ts +30 -22
- package/src/test.ts +1 -1
- package/test/auth.test.ts +101 -0
- package/test/contextProvider.test.ts +11 -11
- package/test/controller.test.ts +21 -30
- package/test/dist/auth.test.d.ts.map +1 -0
- package/test/dist/contextProvider.test.d.ts.map +1 -1
- package/test/dist/controller.test.d.ts.map +1 -1
- package/test/dist/date-query.test.d.ts.map +1 -0
- package/test/dist/fixtures.d.ts +26 -12
- package/test/dist/fixtures.d.ts.map +1 -1
- package/test/dist/fixtures.js +12 -10
- package/test/dist/query.test.d.ts.map +1 -1
- package/test/dist/rawQuery.test.d.ts.map +1 -1
- package/test/dist/repository-ext.test.d.ts.map +1 -0
- package/test/dist/requires.test.d.ts.map +1 -1
- package/test/dist/router-generator.test.d.ts.map +1 -0
- package/test/dist/routing-interruptibility.test.d.ts.map +1 -0
- package/test/dist/rpc-e2e-invalidation.test.d.ts.map +1 -0
- package/test/dist/rpc-multi-middleware.test.d.ts.map +1 -1
- package/test/dist/rpc-stream-fullstack.test.d.ts.map +1 -0
- package/test/dist/sql-store.test.d.ts.map +1 -0
- package/test/fixtures.ts +11 -9
- package/test/query.test.ts +216 -34
- package/test/rawQuery.test.ts +23 -19
- package/test/repository-ext.test.ts +60 -0
- package/test/requires.test.ts +6 -6
- package/test/router-generator.test.ts +183 -0
- package/test/routing-interruptibility.test.ts +63 -0
- package/test/rpc-e2e-invalidation.test.ts +251 -0
- package/test/rpc-multi-middleware.test.ts +78 -9
- package/test/rpc-stream-fullstack.test.ts +300 -0
- package/test/sql-store.test.ts +1064 -0
- package/test/validateSample.test.ts +15 -12
- package/tsconfig.examples.json +1 -1
- package/tsconfig.json +0 -1
- package/tsconfig.json.bak +2 -2
- package/tsconfig.src.json +35 -35
- package/tsconfig.test.json +2 -2
- package/dist/Operations.d.ts +0 -55
- package/dist/Operations.d.ts.map +0 -1
- package/dist/Operations.js +0 -102
- package/dist/OperationsRepo.d.ts +0 -41
- package/dist/OperationsRepo.d.ts.map +0 -1
- package/dist/OperationsRepo.js +0 -14
- package/eslint.config.mjs +0 -24
- package/src/Operations.ts +0 -235
- package/src/OperationsRepo.ts +0 -16
package/src/api/routing.ts
CHANGED
|
@@ -2,22 +2,31 @@
|
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
-
import { Config, Effect, Layer, type NonEmptyReadonlyArray, Predicate, S, type Scope } from "effect-app"
|
|
5
|
+
import { Config, Effect, Layer, type NonEmptyReadonlyArray, Predicate, Ref, S, type Scope, Stream } from "effect-app"
|
|
6
|
+
import { getMeta } from "effect-app/client"
|
|
6
7
|
import { type HttpHeaders } from "effect-app/http"
|
|
8
|
+
import { Invalidation } from "effect-app/rpc"
|
|
7
9
|
import { type GetEffectContext, type GetEffectError, type RpcContextMap } from "effect-app/rpc/RpcContextMap"
|
|
8
10
|
import { type TypeTestId } from "effect-app/TypeTest"
|
|
9
11
|
import { typedKeysOf, typedValuesOf } from "effect-app/utils"
|
|
10
12
|
import { type Yieldable } from "effect/Effect"
|
|
11
13
|
import { Rpc, RpcGroup, type RpcSerialization, RpcServer } from "effect/unstable/rpc"
|
|
12
14
|
import { type LayerUtils } from "./layerUtils.js"
|
|
13
|
-
import {
|
|
15
|
+
import { RequestType as RequestTypeAnnotation } from "./routing/middleware.js"
|
|
14
16
|
|
|
15
17
|
export * from "./routing/middleware.js"
|
|
16
18
|
|
|
19
|
+
export const applyRequestTypeInterruptibility = <A, E, R>(
|
|
20
|
+
requestType: "command" | "query",
|
|
21
|
+
effect: Effect.Effect<A, E, R>
|
|
22
|
+
) => requestType === "command" ? Rpc.uninterruptible(effect) : effect
|
|
23
|
+
|
|
17
24
|
// it's the result of extending S.Req setting success, config
|
|
18
25
|
// it's a schema plus some metadata
|
|
19
26
|
export type AnyRequestModule = S.Top & {
|
|
20
27
|
_tag: string // unique identifier for the request module
|
|
28
|
+
type: "command" | "query"
|
|
29
|
+
stream: boolean
|
|
21
30
|
config: any // ?
|
|
22
31
|
success: S.Top // validates the success response
|
|
23
32
|
error: S.Top // validates the failure response
|
|
@@ -65,7 +74,10 @@ interface HandlerBase<Action extends AnyRequestModule, RT extends RequestType, A
|
|
|
65
74
|
new(): {}
|
|
66
75
|
_tag: RT
|
|
67
76
|
stack: string
|
|
68
|
-
handler: (
|
|
77
|
+
handler: (
|
|
78
|
+
req: S.Schema.Type<Action>,
|
|
79
|
+
headers: HttpHeaders.Headers
|
|
80
|
+
) => Effect.Effect<A, E, R> | Stream.Stream<A, E, R>
|
|
69
81
|
}
|
|
70
82
|
|
|
71
83
|
export interface Handler<Action extends AnyRequestModule, RT extends RequestType, R> extends
|
|
@@ -98,35 +110,47 @@ type RpcRouteR<
|
|
|
98
110
|
] ? R
|
|
99
111
|
: never
|
|
100
112
|
|
|
101
|
-
type
|
|
113
|
+
type EffectMatch<
|
|
102
114
|
Resource extends Record<string, any>,
|
|
103
115
|
RequestContextMap extends Record<string, any>,
|
|
104
116
|
RT extends RequestType,
|
|
105
117
|
Key extends keyof Resource
|
|
106
|
-
> =
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
Exclude<R2, GetEffectContext<RequestContextMap, Resource[Key]["config"]>>,
|
|
115
|
-
Scope.Scope
|
|
116
|
-
>
|
|
118
|
+
> = <A extends GetSuccessShape<Resource[Key], RT>, R2 = never, E = never>(
|
|
119
|
+
f: (req: S.Schema.Type<Resource[Key]>) => Effect.Effect<A, E, R2>
|
|
120
|
+
) => Handler<
|
|
121
|
+
Resource[Key],
|
|
122
|
+
RT,
|
|
123
|
+
Exclude<
|
|
124
|
+
Exclude<R2, GetEffectContext<RequestContextMap, Resource[Key]["config"]>>,
|
|
125
|
+
Scope.Scope
|
|
117
126
|
>
|
|
127
|
+
>
|
|
118
128
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
129
|
+
type StreamMatch<
|
|
130
|
+
Resource extends Record<string, any>,
|
|
131
|
+
RequestContextMap extends Record<string, any>,
|
|
132
|
+
RT extends RequestType,
|
|
133
|
+
Key extends keyof Resource
|
|
134
|
+
> = <A extends GetSuccessShape<Resource[Key], RT>, R2 = never, E = never>(
|
|
135
|
+
f: (req: S.Schema.Type<Resource[Key]>) => Stream.Stream<A, E, R2>
|
|
136
|
+
) => Handler<
|
|
137
|
+
Resource[Key],
|
|
138
|
+
RT,
|
|
139
|
+
Exclude<
|
|
140
|
+
Exclude<R2, GetEffectContext<RequestContextMap, Resource[Key]["config"]>>,
|
|
141
|
+
Scope.Scope
|
|
128
142
|
>
|
|
129
|
-
|
|
143
|
+
>
|
|
144
|
+
|
|
145
|
+
// Stream resources only accept Stream / Effect<Stream> handlers; non-stream resources
|
|
146
|
+
// only accept Effect handlers. Discriminated by the request module's `stream` flag.
|
|
147
|
+
type Match<
|
|
148
|
+
Resource extends Record<string, any>,
|
|
149
|
+
RequestContextMap extends Record<string, any>,
|
|
150
|
+
RT extends RequestType,
|
|
151
|
+
Key extends keyof Resource
|
|
152
|
+
> = Resource[Key] extends { stream: true } ? StreamMatch<Resource, RequestContextMap, RT, Key>
|
|
153
|
+
: EffectMatch<Resource, RequestContextMap, RT, Key>
|
|
130
154
|
|
|
131
155
|
export type RouteMatcher<
|
|
132
156
|
RequestContextMap extends Record<string, any>,
|
|
@@ -156,38 +180,81 @@ export const skipOnProd = Effect
|
|
|
156
180
|
})
|
|
157
181
|
.pipe(Effect.orDie)
|
|
158
182
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
>
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
183
|
+
// Type helpers to extract middleware information from a resource's request classes.
|
|
184
|
+
type MiddlewareOf<M extends Record<string, any>> = Exclude<
|
|
185
|
+
{ [K in keyof M]: M[K] extends { readonly middleware?: infer MW } ? NonNullable<MW> : never }[keyof M],
|
|
186
|
+
never
|
|
187
|
+
>
|
|
188
|
+
type ProvidesOf<MW> = MW extends { readonly provides: infer P } ? P : never
|
|
189
|
+
type RequestContextMapOf<MW> = MW extends {
|
|
190
|
+
requestContextMap: infer RCM extends Record<string, RpcContextMap.Any>
|
|
191
|
+
} ? RCM
|
|
192
|
+
: Record<string, never>
|
|
193
|
+
type LayerNormalize<L> = L extends Layer.Layer<any, infer E, infer R> ? Layer.Layer<never, E, R>
|
|
194
|
+
: Layer.Layer<never, never, never>
|
|
195
|
+
type LayerSuccess<L> = L extends Layer.Layer<infer A, any, any> ? A : never
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Middleware tags are typically passed to `makeRpcClient` as the class value, so
|
|
199
|
+
* the captured `MW` is a constructor type. Layers carry the *instance* type as
|
|
200
|
+
* their success channel. Bridge the two so the constraint compares like-with-like.
|
|
201
|
+
*
|
|
202
|
+
* Effect middleware classes declare `new(_: never): Shape` which the standard
|
|
203
|
+
* `T extends abstract new (...args: any) => infer I` form sometimes fails to
|
|
204
|
+
* narrow. Use the `prototype` member instead — it is always the instance type.
|
|
205
|
+
*/
|
|
206
|
+
type MWService<MW> = MW extends { readonly prototype: infer P } ? P : MW
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Type-level guard: emits a structural mismatch on `Resource` when the middleware
|
|
210
|
+
* service identifier extracted from the resource's request classes is not provided
|
|
211
|
+
* by the layer passed to `makeRouter`. When `MW` is `never` (no middleware on the
|
|
212
|
+
* resource) or already a subtype of the layer's success, this resolves to `unknown`
|
|
213
|
+
* and intersects harmlessly with `Resource`.
|
|
214
|
+
*/
|
|
215
|
+
type EnsureMiddlewareProvided<Live, MW> = [MW] extends [never] ? unknown
|
|
216
|
+
: [MWService<MW>] extends [LayerSuccess<Live>] ? unknown
|
|
217
|
+
: {
|
|
218
|
+
readonly __middlewareNotProvidedByRouterLayer: {
|
|
219
|
+
readonly expected: MWService<MW>
|
|
220
|
+
readonly providedByLayer: LayerSuccess<Live>
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Safe wrappers that check the constraint before calling GetEffectContext/GetEffectError.
|
|
225
|
+
// These avoid TypeScript constraint errors when the RC map type is deferred (generic).
|
|
226
|
+
type SafeGetEffectContext<RCM, Config> = RCM extends Record<string, RpcContextMap.Any> ? GetEffectContext<RCM, Config>
|
|
227
|
+
: never
|
|
228
|
+
type SafeGetEffectError<RCM, Config> = RCM extends Record<string, RpcContextMap.Any> ? GetEffectError<RCM, Config>
|
|
229
|
+
: never
|
|
230
|
+
|
|
231
|
+
export const makeRouter = <Live extends Layer.Layer<any, any, any> = Layer.Layer<any, never, never>>(
|
|
232
|
+
middlewareLive?: Live
|
|
179
233
|
) => {
|
|
234
|
+
type ResourceMWDefault = LayerNormalize<Live>
|
|
235
|
+
|
|
180
236
|
/**
|
|
181
|
-
* Create a Router for specified resource
|
|
182
|
-
*
|
|
237
|
+
* Create a Router for specified resource.
|
|
238
|
+
* Middleware schema/tag is read from the request classes (stored via `makeRpcClient`).
|
|
239
|
+
* The middleware **Live** layer is the one passed to `makeRouter`.
|
|
240
|
+
* If `check` is provided, the router will only be created if the effect succeeds with true.
|
|
183
241
|
*/
|
|
184
242
|
function matchFor<
|
|
185
|
-
const
|
|
186
|
-
|
|
243
|
+
const Resource extends Record<string, any>,
|
|
244
|
+
MW = MiddlewareOf<Resource>
|
|
187
245
|
>(
|
|
188
|
-
rsc: Resource &
|
|
246
|
+
rsc: Resource & EnsureMiddlewareProvided<Live, MW>,
|
|
189
247
|
options?: { check?: Effect.Effect<boolean> }
|
|
190
248
|
) {
|
|
249
|
+
// MW is a defaulted type parameter so TypeScript evaluates MiddlewareOf<Resource>
|
|
250
|
+
// eagerly at each call site, producing a concrete type instead of a deferred conditional.
|
|
251
|
+
type ResourceRequestContextMap = RequestContextMapOf<MW>
|
|
252
|
+
type ResourceContextProviderA = ProvidesOf<MW>
|
|
253
|
+
|
|
254
|
+
type HandlerContext<Action extends AnyRequestModule> =
|
|
255
|
+
| SafeGetEffectContext<ResourceRequestContextMap, Action["config"]>
|
|
256
|
+
| ResourceContextProviderA
|
|
257
|
+
|
|
191
258
|
type HandlerWithInputGen<
|
|
192
259
|
Action extends AnyRequestModule,
|
|
193
260
|
RT extends RequestType
|
|
@@ -200,7 +267,7 @@ export const makeRouter = <
|
|
|
200
267
|
S.Schema.Type<GetFailure<Action>> | S.SchemaError,
|
|
201
268
|
// the actual implementation of the handler may just require the dynamic context provided by the middleware
|
|
202
269
|
// and the per request context provided by the context provider
|
|
203
|
-
|
|
270
|
+
HandlerContext<Action>
|
|
204
271
|
>,
|
|
205
272
|
GetSuccessShape<Action, RT>,
|
|
206
273
|
never
|
|
@@ -216,40 +283,41 @@ export const makeRouter = <
|
|
|
216
283
|
S.Schema.Type<GetFailure<Action>> | S.SchemaError,
|
|
217
284
|
// the actual implementation of the handler may just require the dynamic context provided by the middleware
|
|
218
285
|
// and the per request context provided by the context provider
|
|
219
|
-
|
|
286
|
+
HandlerContext<Action>
|
|
220
287
|
>
|
|
221
288
|
|
|
222
|
-
type
|
|
289
|
+
type HandlerWithInputStream<
|
|
223
290
|
Action extends AnyRequestModule,
|
|
224
291
|
RT extends RequestType
|
|
225
|
-
> =
|
|
292
|
+
> = (
|
|
293
|
+
req: S.Schema.Type<Action>
|
|
294
|
+
) => Stream.Stream<
|
|
226
295
|
GetSuccessShape<Action, RT>,
|
|
227
296
|
S.Schema.Type<GetFailure<Action>> | S.SchemaError,
|
|
228
|
-
|
|
229
|
-
// and the per request context provided by the context provider
|
|
230
|
-
GetEffectContext<RequestContextMap, Action["config"]> | ContextProviderA
|
|
297
|
+
HandlerContext<Action>
|
|
231
298
|
>
|
|
232
299
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
|
300
|
+
// Stream resources only accept `(req) => Stream`; non-stream only Effect / Generator.
|
|
301
|
+
type Handlers<Action extends AnyRequestModule, RT extends RequestType> = Action extends { stream: true }
|
|
302
|
+
? HandlerWithInputStream<Action, RT>
|
|
303
|
+
: HandlerWithInputGen<Action, RT> | HandlerWithInputEff<Action, RT>
|
|
237
304
|
|
|
238
305
|
type HandlersDecoded<Action extends AnyRequestModule> = Handlers<Action, RequestTypes.DECODED>
|
|
239
306
|
|
|
240
|
-
type HandlersRaw<Action extends AnyRequestModule> =
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
307
|
+
type HandlersRaw<Action extends AnyRequestModule> = Action extends { stream: true }
|
|
308
|
+
? { raw: HandlerWithInputStream<Action, RequestTypes.RAW> }
|
|
309
|
+
:
|
|
310
|
+
| { raw: HandlerWithInputGen<Action, RequestTypes.RAW> }
|
|
311
|
+
| { raw: HandlerWithInputEff<Action, RequestTypes.RAW> }
|
|
244
312
|
|
|
245
313
|
type AnyHandlers<Action extends AnyRequestModule> = HandlersRaw<Action> | HandlersDecoded<Action>
|
|
246
314
|
|
|
247
|
-
const
|
|
315
|
+
const meta = getMeta(rsc)
|
|
248
316
|
|
|
249
317
|
type RequestModules = FilterRequestModules<Resource>
|
|
250
318
|
const requestModules = typedKeysOf(rsc).reduce((acc, cur) => {
|
|
251
319
|
if (Predicate.isObjectKeyword(rsc[cur]) && rsc[cur]["success"]) {
|
|
252
|
-
acc[cur as keyof RequestModules] = rsc[cur]
|
|
320
|
+
acc[cur as keyof RequestModules] = rsc[cur]
|
|
253
321
|
}
|
|
254
322
|
return acc
|
|
255
323
|
}, {} as RequestModules)
|
|
@@ -260,19 +328,13 @@ export const makeRouter = <
|
|
|
260
328
|
// handlerImpl is the actual handler implementation
|
|
261
329
|
if (handlerImpl[Symbol.toStringTag] === "GeneratorFunction") handlerImpl = Effect.fnUntraced(handlerImpl)
|
|
262
330
|
const stack = new Error().stack?.split("\n").slice(2).join("\n")
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
: class {
|
|
271
|
-
static request = rsc[cur]
|
|
272
|
-
static stack = stack
|
|
273
|
-
static _tag = RequestTypes.DECODED
|
|
274
|
-
static handler = handlerImpl
|
|
275
|
-
}
|
|
331
|
+
// oxlint-disable-next-line typescript/no-extraneous-class
|
|
332
|
+
return class {
|
|
333
|
+
static request = rsc[cur]
|
|
334
|
+
static stack = stack
|
|
335
|
+
static _tag = RequestTypes.DECODED
|
|
336
|
+
static handler = handlerImpl
|
|
337
|
+
}
|
|
276
338
|
}, {
|
|
277
339
|
success: rsc[cur].success,
|
|
278
340
|
successRaw: S.toEncoded(rsc[cur].success),
|
|
@@ -283,24 +345,18 @@ export const makeRouter = <
|
|
|
283
345
|
(handlerImpl: any) => {
|
|
284
346
|
if (handlerImpl[Symbol.toStringTag] === "GeneratorFunction") handlerImpl = Effect.fnUntraced(handlerImpl)
|
|
285
347
|
const stack = new Error().stack?.split("\n").slice(2).join("\n")
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
: class {
|
|
294
|
-
static request = rsc[cur]
|
|
295
|
-
static stack = stack
|
|
296
|
-
static _tag = RequestTypes.RAW
|
|
297
|
-
static handler = handlerImpl
|
|
298
|
-
}
|
|
348
|
+
// oxlint-disable-next-line typescript/no-extraneous-class
|
|
349
|
+
return class {
|
|
350
|
+
static request = rsc[cur]
|
|
351
|
+
static stack = stack
|
|
352
|
+
static _tag = RequestTypes.RAW
|
|
353
|
+
static handler = handlerImpl
|
|
354
|
+
}
|
|
299
355
|
}
|
|
300
356
|
})
|
|
301
357
|
return prev
|
|
302
358
|
},
|
|
303
|
-
{} as RouteMatcher<
|
|
359
|
+
{} as RouteMatcher<ResourceRequestContextMap, Resource>
|
|
304
360
|
)
|
|
305
361
|
|
|
306
362
|
const router3: <
|
|
@@ -318,23 +374,19 @@ export const makeRouter = <
|
|
|
318
374
|
// retrieves context R from the actual implementation of the handler
|
|
319
375
|
Impl[K] extends { raw: any }
|
|
320
376
|
? Impl[K]["raw"] extends (...args: any[]) => Effect.Effect<any, any, infer R> ? R
|
|
321
|
-
: Impl[K]["raw"] extends
|
|
377
|
+
: Impl[K]["raw"] extends (...args: any[]) => Stream.Stream<any, any, infer R> ? R
|
|
322
378
|
: Impl[K]["raw"] extends (...args: any[]) => Generator<
|
|
323
|
-
Yieldable<any, any, any, infer R
|
|
324
|
-
any,
|
|
325
|
-
any
|
|
379
|
+
Yieldable<any, any, any, infer R>
|
|
326
380
|
> ? R
|
|
327
381
|
: never
|
|
328
382
|
: Impl[K] extends (...args: any[]) => Effect.Effect<any, any, infer R> ? R
|
|
329
|
-
: Impl[K] extends
|
|
383
|
+
: Impl[K] extends (...args: any[]) => Stream.Stream<any, any, infer R> ? R
|
|
330
384
|
: Impl[K] extends (...args: any[]) => Generator<
|
|
331
|
-
Yieldable<any, any, any, infer R
|
|
332
|
-
any,
|
|
333
|
-
any
|
|
385
|
+
Yieldable<any, any, any, infer R>
|
|
334
386
|
> ? R
|
|
335
387
|
: never,
|
|
336
|
-
|
|
|
337
|
-
|
|
|
388
|
+
| SafeGetEffectContext<ResourceRequestContextMap, Resource[K]["config"]>
|
|
389
|
+
| ResourceContextProviderA
|
|
338
390
|
>,
|
|
339
391
|
Scope.Scope
|
|
340
392
|
>
|
|
@@ -359,7 +411,7 @@ export const makeRouter = <
|
|
|
359
411
|
match: any
|
|
360
412
|
) =>
|
|
361
413
|
| Effect.Effect<THandlers, MakeE, MakeR>
|
|
362
|
-
| Generator<Yieldable<any, any, MakeE, MakeR>, THandlers
|
|
414
|
+
| Generator<Yieldable<any, any, MakeE, MakeR>, THandlers>
|
|
363
415
|
) => {
|
|
364
416
|
const dependenciesL = (dependencies ? Layer.mergeAll(...dependencies as any) : Layer.empty) as Layer.Layer<
|
|
365
417
|
LayerUtils.GetLayersSuccess<MakeDependencies>,
|
|
@@ -375,6 +427,9 @@ export const makeRouter = <
|
|
|
375
427
|
|
|
376
428
|
const controllers = yield* finalMake
|
|
377
429
|
|
|
430
|
+
// Read the middleware from the resource's request classes at runtime
|
|
431
|
+
const mw = meta.middleware as any
|
|
432
|
+
|
|
378
433
|
// return make.pipe(Effect.map((c) => controllers(c, dependencies)))
|
|
379
434
|
const mapped = typedKeysOf(requestModules).reduce((acc, cur) => {
|
|
380
435
|
const handler = controllers[cur as keyof typeof controllers]
|
|
@@ -386,12 +441,109 @@ export const makeRouter = <
|
|
|
386
441
|
static success = S.toEncoded(resource.success)
|
|
387
442
|
} as any
|
|
388
443
|
: resource,
|
|
389
|
-
(payload: any, headers: any) =>
|
|
390
|
-
|
|
391
|
-
|
|
444
|
+
(payload: any, headers: any) => {
|
|
445
|
+
const result: any = handler.handler(payload, headers)
|
|
446
|
+
if (resource.stream) {
|
|
447
|
+
// Wrap stream items as { _tag: "value", value } and append a final
|
|
448
|
+
// { _tag: "done", metadata } chunk carrying accumulated invalidation keys.
|
|
449
|
+
// V2: on failure, convert to { _tag: "error", error, metadata } chunk so
|
|
450
|
+
// clients can invalidate queries even when the stream fails.
|
|
451
|
+
const keysRef = Ref.makeUnsafe<ReadonlyArray<Invalidation.InvalidationKey>>([])
|
|
452
|
+
const invalidationSet = Invalidation.makeInvalidationSet(keysRef)
|
|
453
|
+
return Stream.concat(
|
|
454
|
+
(result as Stream.Stream<any, any, any>).pipe(
|
|
455
|
+
Stream.map((item: any) => ({ _tag: "value" as const, value: item })),
|
|
456
|
+
Stream.provideService(Invalidation.InvalidationSet, invalidationSet),
|
|
457
|
+
// V3: after each value chunk, drain accumulated keys and emit a "metadata"
|
|
458
|
+
// chunk if any keys were collected since the last drain. This lets clients
|
|
459
|
+
// invalidate queries mid-stream without waiting for the "done" chunk.
|
|
460
|
+
Stream.flatMap((valueChunk: any) =>
|
|
461
|
+
Stream
|
|
462
|
+
.fromEffect(
|
|
463
|
+
Ref.getAndSet(keysRef, []).pipe(
|
|
464
|
+
Effect.map((keys) =>
|
|
465
|
+
keys.length > 0
|
|
466
|
+
? [
|
|
467
|
+
valueChunk,
|
|
468
|
+
{ _tag: "metadata" as const, metadata: { invalidateQueries: keys } }
|
|
469
|
+
]
|
|
470
|
+
: [valueChunk]
|
|
471
|
+
)
|
|
472
|
+
)
|
|
473
|
+
)
|
|
474
|
+
.pipe(Stream.flatMap(Stream.fromIterable))
|
|
475
|
+
),
|
|
476
|
+
// V2: catch stream failures and embed them in the stream as an error chunk
|
|
477
|
+
Stream.catch((err: any) =>
|
|
478
|
+
Stream.fromEffect(
|
|
479
|
+
Ref.get(keysRef).pipe(
|
|
480
|
+
Effect.flatMap((keys) =>
|
|
481
|
+
Effect.fail({
|
|
482
|
+
_tag: "error" as const,
|
|
483
|
+
error: err,
|
|
484
|
+
metadata: { invalidateQueries: keys }
|
|
485
|
+
})
|
|
486
|
+
)
|
|
487
|
+
)
|
|
488
|
+
)
|
|
489
|
+
)
|
|
490
|
+
),
|
|
491
|
+
Stream.fromEffect(
|
|
492
|
+
Ref.get(keysRef).pipe(
|
|
493
|
+
Effect.map((keys) => ({ _tag: "done" as const, metadata: { invalidateQueries: keys } }))
|
|
494
|
+
)
|
|
495
|
+
)
|
|
496
|
+
)
|
|
497
|
+
}
|
|
498
|
+
let effect = (result as Effect.Effect<unknown, unknown, unknown>).pipe(
|
|
499
|
+
Effect.withSpan(`${meta.moduleName}/${resource._tag}`, {
|
|
500
|
+
kind: "server",
|
|
501
|
+
attributes: {
|
|
502
|
+
"rpc.system": "effect-app",
|
|
503
|
+
"rpc.service": meta.moduleName,
|
|
504
|
+
"rpc.method": resource._tag,
|
|
505
|
+
"code.function.name": resource._tag,
|
|
506
|
+
"code.namespace": meta.moduleName,
|
|
507
|
+
"app.rpc.type": resource.type
|
|
508
|
+
}
|
|
509
|
+
}, {
|
|
392
510
|
captureStackTrace: () => handler.stack // capturing the handler stack is the main reason why we are doing the span here
|
|
393
511
|
})
|
|
394
512
|
)
|
|
513
|
+
|
|
514
|
+
// Commands: provide a request-scoped `InvalidationSet` and wrap both
|
|
515
|
+
// success (`CommandResponseWithMetaData`) and handler-thrown failure
|
|
516
|
+
// (`CommandFailureWithMetaData`) so the client receives accumulated
|
|
517
|
+
// invalidation keys on either path. Middleware-thrown errors bypass the
|
|
518
|
+
// wrap (they fail the outer effect before reaching this `.catch`) and
|
|
519
|
+
// flow raw on the Cause; client decodes them via the rpc's
|
|
520
|
+
// `middlewares[*].error` failure-union channel.
|
|
521
|
+
if (resource.type === "command") {
|
|
522
|
+
const keysRef = Ref.makeUnsafe<ReadonlyArray<Invalidation.InvalidationKey>>([])
|
|
523
|
+
const invalidationSet = Invalidation.makeInvalidationSet(keysRef)
|
|
524
|
+
effect = effect.pipe(
|
|
525
|
+
Effect.provideService(Invalidation.InvalidationSet, invalidationSet),
|
|
526
|
+
Effect.flatMap((value) =>
|
|
527
|
+
Ref.get(keysRef).pipe(
|
|
528
|
+
Effect.map((keys) => ({ payload: value, metadata: { invalidateQueries: keys } }) as any)
|
|
529
|
+
)
|
|
530
|
+
),
|
|
531
|
+
Effect.catch((err: any) =>
|
|
532
|
+
Ref.get(keysRef).pipe(
|
|
533
|
+
Effect.flatMap((keys) =>
|
|
534
|
+
Effect.fail({
|
|
535
|
+
_tag: "CommandFailureWithMetaData" as const,
|
|
536
|
+
error: err,
|
|
537
|
+
metadata: { invalidateQueries: keys }
|
|
538
|
+
})
|
|
539
|
+
)
|
|
540
|
+
)
|
|
541
|
+
)
|
|
542
|
+
)
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
return applyRequestTypeInterruptibility(resource.type, effect)
|
|
546
|
+
}
|
|
395
547
|
] as const
|
|
396
548
|
return acc
|
|
397
549
|
}, {} as any) as {
|
|
@@ -403,10 +555,10 @@ export const makeRouter = <
|
|
|
403
555
|
) => Effect.Effect<
|
|
404
556
|
Effect.Success<ReturnType<THandlers[K]["handler"]>>,
|
|
405
557
|
| Effect.Error<ReturnType<THandlers[K]["handler"]>>
|
|
406
|
-
|
|
|
558
|
+
| SafeGetEffectError<ResourceRequestContextMap, Resource[K]["config"]>,
|
|
407
559
|
Exclude<
|
|
408
560
|
Effect.Services<ReturnType<THandlers[K]["handler"]>>,
|
|
409
|
-
|
|
561
|
+
ResourceContextProviderA | SafeGetEffectContext<ResourceRequestContextMap, Resource[K]["config"]>
|
|
410
562
|
>
|
|
411
563
|
>
|
|
412
564
|
]
|
|
@@ -415,13 +567,33 @@ export const makeRouter = <
|
|
|
415
567
|
const rpcs = RpcGroup
|
|
416
568
|
.make(
|
|
417
569
|
...typedValuesOf(mapped).map(([resource]) => {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
570
|
+
const isStream = resource.stream
|
|
571
|
+
const isCommand = resource.type === "command"
|
|
572
|
+
return (isCommand
|
|
573
|
+
? isStream
|
|
574
|
+
? Invalidation.makeStreamRpc(resource._tag, {
|
|
575
|
+
payload: resource,
|
|
576
|
+
success: resource.success,
|
|
577
|
+
error: resource.error,
|
|
578
|
+
stream: true as const
|
|
579
|
+
})
|
|
580
|
+
: Invalidation.makeCommandRpc(resource._tag, {
|
|
581
|
+
payload: resource,
|
|
582
|
+
success: resource.success,
|
|
583
|
+
error: resource.error
|
|
584
|
+
})
|
|
585
|
+
: Rpc.make(resource._tag, {
|
|
586
|
+
payload: resource,
|
|
587
|
+
success: resource.success,
|
|
588
|
+
error: resource.error,
|
|
589
|
+
stream: isStream
|
|
590
|
+
}))
|
|
591
|
+
.annotate(mw.requestContext, resource.config ?? {})
|
|
592
|
+
.annotate(RequestTypeAnnotation, resource.type)
|
|
421
593
|
})
|
|
422
594
|
)
|
|
423
595
|
.prefix(`${meta.moduleName}.`)
|
|
424
|
-
.middleware(
|
|
596
|
+
.middleware(mw)
|
|
425
597
|
|
|
426
598
|
const rpc = rpcs
|
|
427
599
|
.toLayer(Effect.gen(function*() {
|
|
@@ -449,7 +621,7 @@ export const makeRouter = <
|
|
|
449
621
|
const routes = layer.pipe(
|
|
450
622
|
Layer.provide([
|
|
451
623
|
dependenciesL,
|
|
452
|
-
|
|
624
|
+
(middlewareLive ?? Layer.empty) as Layer.Layer<any, any, any>
|
|
453
625
|
])
|
|
454
626
|
)
|
|
455
627
|
|
|
@@ -479,8 +651,7 @@ export const makeRouter = <
|
|
|
479
651
|
any,
|
|
480
652
|
any
|
|
481
653
|
>,
|
|
482
|
-
{ [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> }
|
|
483
|
-
any
|
|
654
|
+
{ [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> }
|
|
484
655
|
>
|
|
485
656
|
/** @deprecated */
|
|
486
657
|
readonly ಠ_ಠ: never
|
|
@@ -492,9 +663,9 @@ export const makeRouter = <
|
|
|
492
663
|
never,
|
|
493
664
|
| MakeErrors<Make>
|
|
494
665
|
| MakeDepsE<Make>
|
|
495
|
-
| Layer.Error<
|
|
666
|
+
| Layer.Error<ResourceMWDefault>,
|
|
496
667
|
| MakeDepsIn<Make>
|
|
497
|
-
| Layer.Services<
|
|
668
|
+
| Layer.Services<ResourceMWDefault>
|
|
498
669
|
| Exclude<
|
|
499
670
|
MakeContext<Make>,
|
|
500
671
|
MakeDepsOut<Make>
|
|
@@ -511,8 +682,7 @@ export const makeRouter = <
|
|
|
511
682
|
// v4: generators yield Yieldable with asEffect()
|
|
512
683
|
effect: (match: typeof router3) => Generator<
|
|
513
684
|
Yieldable<any, any, any, any>,
|
|
514
|
-
{ [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> }
|
|
515
|
-
any
|
|
685
|
+
{ [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> }
|
|
516
686
|
>
|
|
517
687
|
}
|
|
518
688
|
>(
|
|
@@ -522,9 +692,9 @@ export const makeRouter = <
|
|
|
522
692
|
never,
|
|
523
693
|
| MakeErrors<Make>
|
|
524
694
|
| MakeDepsE<Make>
|
|
525
|
-
| Layer.Error<
|
|
695
|
+
| Layer.Error<ResourceMWDefault>,
|
|
526
696
|
| MakeDepsIn<Make>
|
|
527
|
-
| Layer.Services<
|
|
697
|
+
| Layer.Services<ResourceMWDefault>
|
|
528
698
|
| Exclude<
|
|
529
699
|
MakeContext<Make>,
|
|
530
700
|
MakeDepsOut<Make>
|
|
@@ -572,23 +742,23 @@ export type MakeErrors<Make> = /*Make extends { readonly effect: (_: any) => Eff
|
|
|
572
742
|
: Make extends { readonly effect: (_: any) => Effect.Effect<any, never, any> } ? never
|
|
573
743
|
: */
|
|
574
744
|
// v4: generators yield Yieldable with asEffect()
|
|
575
|
-
Make extends { readonly effect: (_: any) => Generator<Yieldable<any, any, never, any
|
|
576
|
-
: Make extends { readonly effect: (_: any) => Generator<Yieldable<any, any, infer E, any
|
|
745
|
+
Make extends { readonly effect: (_: any) => Generator<Yieldable<any, any, never, any>> } ? never
|
|
746
|
+
: Make extends { readonly effect: (_: any) => Generator<Yieldable<any, any, infer E, any>> } ? E
|
|
577
747
|
: never
|
|
578
748
|
|
|
579
749
|
export type MakeContext<Make> = /*Make extends { readonly effect: (_: any) => Effect.Effect<any, any, infer R> } ? R
|
|
580
750
|
: Make extends { readonly effect: (_: any) => Effect.Effect<any, any, never> } ? never
|
|
581
751
|
: */
|
|
582
752
|
// v4: generators yield Yieldable with asEffect()
|
|
583
|
-
Make extends { readonly effect: (_: any) => Generator<Yieldable<any, any, any
|
|
584
|
-
: Make extends { readonly effect: (_: any) => Generator<Yieldable<any, any, any, infer R
|
|
753
|
+
Make extends { readonly effect: (_: any) => Generator<Yieldable<any, any, any>> } ? never
|
|
754
|
+
: Make extends { readonly effect: (_: any) => Generator<Yieldable<any, any, any, infer R>> } ? R
|
|
585
755
|
: never
|
|
586
756
|
|
|
587
757
|
export type MakeHandlers<Make, _Handlers extends Record<string, any>> = /*Make extends
|
|
588
758
|
{ readonly effect: (_: any) => Effect.Effect<{ [K in keyof Handlers]: AnyHandler<Handlers[K]> }, any, any> }
|
|
589
759
|
? Effect.Success<ReturnType<Make["effect"]>>
|
|
590
760
|
: */
|
|
591
|
-
Make extends { readonly effect: (_: any) => Generator<any, infer S
|
|
761
|
+
Make extends { readonly effect: (_: any) => Generator<any, infer S> } ? S
|
|
592
762
|
: never
|
|
593
763
|
|
|
594
764
|
export type MakeDepsE<Make> = Layer.Error<MakeDeps<Make>>
|