( middlewareLive?: Live )
| 236 | : never |
| 237 | |
| 238 | export const makeRouter = <Live extends Layer.Layer<any, any, any> = Layer.Layer<any, never, never>>( |
| 239 | middlewareLive?: Live |
| 240 | ) => { |
| 241 | type ResourceMWDefault = LayerNormalize<Live> |
| 242 | |
| 243 | /** |
| 244 | * Create a Router for specified resource. |
| 245 | * Middleware schema/tag is read from the request classes (stored via `makeRpcClient`). |
| 246 | * The middleware **Live** layer is the one passed to `makeRouter`. |
| 247 | * If `check` is provided, the router will only be created if the effect succeeds with true. |
| 248 | */ |
| 249 | function matchFor< |
| 250 | const Resource extends Record<string, any>, |
| 251 | MW = MiddlewareOf<Resource> |
| 252 | >( |
| 253 | rsc: Resource & EnsureMiddlewareProvided<Live, MW>, |
| 254 | options?: { check?: Effect.Effect<boolean> } |
| 255 | ) { |
| 256 | // MW is a defaulted type parameter so TypeScript evaluates MiddlewareOf<Resource> |
| 257 | // eagerly at each call site, producing a concrete type instead of a deferred conditional. |
| 258 | type ResourceRequestContextMap = RequestContextMapOf<MW> |
| 259 | type ResourceContextProviderA = ProvidesOf<MW> |
| 260 | |
| 261 | type HandlerContext<Action extends AnyRequestModule> = |
| 262 | | SafeGetEffectContext<ResourceRequestContextMap, Action["config"]> |
| 263 | | ResourceContextProviderA |
| 264 | |
| 265 | type HandlerWithInputGen< |
| 266 | Action extends AnyRequestModule, |
| 267 | RT extends RequestType |
| 268 | > = ( |
| 269 | req: Action["Type"] |
| 270 | ) => Generator< |
| 271 | Effect.Effect< |
| 272 | any, |
| 273 | GetFailure<Action>["Type"] | S.SchemaError, |
| 274 | // the actual implementation of the handler may just require the dynamic context provided by the middleware |
| 275 | // and the per request context provided by the context provider |
| 276 | HandlerContext<Action> |
| 277 | >, |
| 278 | GetSuccessShape<Action, RT>, |
| 279 | never |
| 280 | > |
| 281 | |
| 282 | type HandlerWithInputEff< |
| 283 | Action extends AnyRequestModule, |
| 284 | RT extends RequestType |
| 285 | > = ( |
| 286 | req: Action["Type"] |
| 287 | ) => Effect.Effect< |
| 288 | GetSuccessShape<Action, RT>, |
| 289 | GetFailure<Action>["Type"] | S.SchemaError, |
| 290 | // the actual implementation of the handler may just require the dynamic context provided by the middleware |
| 291 | // and the per request context provided by the context provider |
| 292 | HandlerContext<Action> |
| 293 | > |
| 294 | |
| 295 | type HandlerWithInputStream< |
no outgoing calls
no test coverage detected
searching dependent graphs…