import { Hono } from "hono"; import { mskService, type CreateMskClusterInput, type CreateTopicInput, type ProduceMessageInput, } from "../services/msk"; type MskService = typeof mskService; export function createMskRouter(service: MskService = mskService) { const app = new Hono(); app.get("/clusters", async (c) => c.json(await service.listClusters())); app.post("/clusters", async (c) => c.json(await service.createCluster(await c.req.json()), 201)); app.delete("/clusters/:clusterArn", async (c) => { await service.deleteCluster(c.req.param("clusterArn")); return c.json({ state: "DELETING" }); }); app.get("/clusters/:clusterArn/bootstrap-brokers", async (c) => c.json({bootstrapBrokers: await service.getBootstrapBrokers(c.req.param("clusterArn"))})); app.get("/clusters/:clusterArn/topics", async (c) => c.json(await service.listTopics(c.req.param("clusterArn")))); app.post("/clusters/:clusterArn/topics", async (c) => c.json(await service.createTopic(c.req.param("clusterArn"), await c.req.json()), 201)); app.delete("/clusters/:clusterArn/topics/:topic", async (c) => c.json(await service.deleteTopic(c.req.param("clusterArn"), c.req.param("topic")))); app.post("/clusters/:clusterArn/topics/:topic/messages", async (c) => c.json(await service.produceMessage(c.req.param("clusterArn"), c.req.param("topic"), await c.req.json()), 201)); app.get("/clusters/:clusterArn/topics/:topic/messages", async (c) => c.json(await service.peekMessages(c.req.param("clusterArn"), c.req.param("topic"), Number(c.req.query("limit") ?? 50)))); app.get("/clusters/:clusterArn/consumer-groups/:groupId/lag", async (c) => c.json(await service.consumerGroupLag(c.req.param("clusterArn"), c.req.param("groupId"), c.req.query("topic")))); return app; } export default createMskRouter();