(
api: HttpApi.HttpApi<ApiId, Groups>,
groupIdentifier: Identifier,
build: (
handlers: Handlers.FromGroup<HttpApiGroup.WithIdentifier<Groups, Identifier>>
) => Handlers.ValidateReturn<Return>
)
| 118 | * @since 4.0.0 |
| 119 | */ |
| 120 | export 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 | |
| 157 | const HandlersTypeId = "~effect/httpapi/HttpApiBuilder/Handlers" |
| 158 |
nothing calls this directly
no test coverage detected