refactor(file): use effectful HttpApi group builder

Build the file HttpApi handlers with an effectful group callback so the file service is resolved once at layer construction time and the endpoint handlers close over the resulting methods.
This commit is contained in:
Kit Langton 2026-04-14 19:40:05 -04:00
commit e34bbb394d

View file

@ -58,24 +58,27 @@ const Api = HttpApi.make("file")
}), }),
) )
const list = Effect.fn("FileHttpApi.list")(function* (ctx: { query: { path?: string } }) { const FileLive = HttpApiBuilder.group(
Api,
"file",
Effect.fn("FileHttpApi.handlers")(function* (handlers) {
const svc = yield* File.Service const svc = yield* File.Service
const list = Effect.fn("FileHttpApi.list")(function* (ctx: { query: { path?: string } }) {
return Schema.decodeUnknownSync(Schema.Array(File.Node))(yield* svc.list(ctx.query.path)) return Schema.decodeUnknownSync(Schema.Array(File.Node))(yield* svc.list(ctx.query.path))
}) })
const content = Effect.fn("FileHttpApi.content")(function* (ctx: { query: { path: string } }) { const content = Effect.fn("FileHttpApi.content")(function* (ctx: { query: { path: string } }) {
const svc = yield* File.Service
return Schema.decodeUnknownSync(File.Content)(yield* svc.read(ctx.query.path)) return Schema.decodeUnknownSync(File.Content)(yield* svc.read(ctx.query.path))
}) })
const status = Effect.fn("FileHttpApi.status")(function* () { const status = Effect.fn("FileHttpApi.status")(function* () {
const svc = yield* File.Service
return Schema.decodeUnknownSync(Schema.Array(File.Info))(yield* svc.status()) return Schema.decodeUnknownSync(Schema.Array(File.Info))(yield* svc.status())
}) })
const FileLive = HttpApiBuilder.group(Api, "file", (handlers) => return handlers.handle("list", list).handle("content", content).handle("status", status)
handlers.handle("list", list).handle("content", content).handle("status", status), }),
) ).pipe(Layer.provide(File.defaultLayer))
const web = lazy(() => const web = lazy(() =>
HttpRouter.toWebHandler( HttpRouter.toWebHandler(