MCPcopy Index your code
hub / github.com/Effect-TS/effect / group

Function group

packages/platform/src/HttpApiBuilder.ts:458–507  ·  view source on GitHub ↗
(
  api: HttpApi.HttpApi<ApiId, Groups, ApiError, ApiR>,
  groupName: Name,
  build: (
    handlers: Handlers.FromGroup<ApiError, ApiR, HttpApiGroup.HttpApiGroup.WithName<Groups, Name>>
  ) => Handlers.ValidateReturn<Return>
)

Source from the content-addressed store, hash-verified

456 * @category handlers
457 */
458export const group = <
459 ApiId extends string,
460 Groups extends HttpApiGroup.HttpApiGroup.Any,
461 ApiError,
462 ApiR,
463 const Name extends HttpApiGroup.HttpApiGroup.Name<Groups>,
464 Return
465>(
466 api: HttpApi.HttpApi<ApiId, Groups, ApiError, ApiR>,
467 groupName: Name,
468 build: (
469 handlers: Handlers.FromGroup<ApiError, ApiR, HttpApiGroup.HttpApiGroup.WithName<Groups, Name>>
470 ) => Handlers.ValidateReturn<Return>
471): Layer.Layer<
472 HttpApiGroup.ApiGroup<ApiId, Name>,
473 Handlers.Error<Return>,
474 Exclude<
475 | Handlers.Context<Return>
476 | HttpApiGroup.HttpApiGroup.MiddlewareWithName<Groups, Name>,
477 Scope
478 >
479> =>
480 Router.use((router) =>
481 Effect.gen(function*() {
482 const context = yield* Effect.context<any>()
483 const group = api.groups[groupName]!
484 const result = build(makeHandlers({ group, handlers: Chunk.empty() }))
485 const handlers: Handlers<any, any, any> = Effect.isEffect(result)
486 ? (yield* result as Effect.Effect<any, any, any>)
487 : result
488 const groupMiddleware = makeMiddlewareMap((group as any).middlewares, context)
489 const routes: Array<HttpRouter.Route<any, any>> = []
490 for (const item of handlers.handlers) {
491 const middleware = makeMiddlewareMap((item as any).endpoint.middlewares, context, groupMiddleware)
492 routes.push(handlerToRoute(
493 item.endpoint,
494 middleware,
495 function(request) {
496 return Effect.mapInputContext(
497 item.handler(request),
498 (input) => Context.merge(context, input)
499 )
500 },
501 item.withFullRequest,
502 item.uninterruptible
503 ))
504 }
505 yield* router.concat(HttpRouter.fromIterable(routes))
506 })
507 ) as any
508
509/**
510 * Create a `Handler` for a single endpoint.

Callers

nothing calls this directly

Calls 6

buildFunction · 0.85
makeMiddlewareMapFunction · 0.85
handlerToRouteFunction · 0.85
mergeMethod · 0.80
makeHandlersFunction · 0.70
contextMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…