MCPcopy Create free account
hub / github.com/Effect-TS/effect / group

Function group

packages/effect/src/unstable/httpapi/HttpApiBuilder.ts:120–155  ·  view source on GitHub ↗
(
  api: HttpApi.HttpApi<ApiId, Groups>,
  groupIdentifier: Identifier,
  build: (
    handlers: Handlers.FromGroup<HttpApiGroup.WithIdentifier<Groups, Identifier>>
  ) => Handlers.ValidateReturn<Return>
)

Source from the content-addressed store, hash-verified

118 * @since 4.0.0
119 */
120export const group = <
121 ApiId extends string,
122 Groups extends HttpApiGroup.Constraint,
123 const Identifier extends HttpApiGroup.Identifier<Groups>,
124 Return
125>(
126 api: HttpApi.HttpApi<ApiId, Groups>,
127 groupIdentifier: Identifier,
128 build: (
129 handlers: Handlers.FromGroup<HttpApiGroup.WithIdentifier<Groups, Identifier>>
130 ) => Handlers.ValidateReturn<Return>
131): Layer.Layer<
132 HttpApiGroup.Service<ApiId, Identifier>,
133 Handlers.Error<Return>,
134 Exclude<Handlers.Context<Return>, Scope.Scope>
135> =>
136 Layer.effectContext(Effect.gen(function*() {
137 const services = (yield* Effect.context<any>()).pipe(
138 Context.omit(Scope.Scope)
139 )
140 const group = api.groups[groupIdentifier] as HttpApiGroup.Constraint
141 const result = build(makeHandlers(group))
142 const handlers: Handlers<any, any, any> = Effect.isEffect(result)
143 ? (yield* result as Effect.Effect<any, any, any>)
144 : result
145 const routes: Array<HttpRouter.Route<any, any>> = []
146 for (const item of handlers.handlers.values()) {
147 routes.push(handlerToRoute(group as any, item, services))
148 }
149 return Context.makeUnsafe(
150 new Map([[group.key, {
151 routes,
152 handlers: handlers.handlers
153 }]])
154 )
155 })) as any
156
157const HandlersTypeId = "~effect/httpapi/HttpApiBuilder/Handlers"
158

Callers

nothing calls this directly

Calls 7

handlerToRouteFunction · 0.85
contextMethod · 0.80
pushMethod · 0.80
makeHandlersFunction · 0.70
pipeMethod · 0.65
omitMethod · 0.65
buildFunction · 0.50

Tested by

no test coverage detected