MCPcopy Create free account
hub / github.com/effect-app/libs / matchFor

Function matchFor

packages/infra/src/routing.ts:249–768  ·  view source on GitHub ↗

* Create a Router for specified resource. * Middleware schema/tag is read from the request classes (stored via `makeRpcClient`). * The middleware **Live** layer is the one passed to `makeRouter`. * If `check` is provided, the router will only be created if the effect succeeds with true.

(
    rsc: Resource & EnsureMiddlewareProvided<Live, MW>,
    options?: { check?: Effect.Effect<boolean> }
  )

Source from the content-addressed store, hash-verified

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<
296 Action extends AnyRequestModule,
297 RT extends RequestType
298 > = (
299 req: Action["Type"]
300 ) => Stream.Stream<
301 GetSuccessShape<Action, RT>,
302 GetFailure<Action>["Type"] | S.SchemaError,
303 HandlerContext<Action>
304 >
305
306 // Stream resources only accept `(req) => Stream`; non-stream only Effect / Generator.

Callers

nothing calls this directly

Calls 5

getMetaFunction · 0.90
typedKeysOfFunction · 0.90
makeRoutesFunction · 0.85
joinMethod · 0.80
splitMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…