import { trpcServer } from "@hono/trpc-server";
import { initTRPC } from "@trpc/server";
import { Hono } from "hono";
import { createClient } from "rivetkit/client";
import { z } from "zod";
import { registry } from "./index.ts";
const client = createClient<typeof registry>();
const t = initTRPC.create();
const appRouter = t.router({
increment: t.procedure
.input(z.object({ name: z.string() }))
.mutation(async ({ input }) => {
const counter = client.counter.getOrCreate(input.name);
const newCount = await counter.increment(1);
return newCount;
}),
});
export type AppRouter = typeof appRouter;
const app = new Hono();
app.use("/trpc/*", trpcServer({ router: appRouter }));
app.all("/api/rivet/*", (c) => registry.handler(c.req.raw));
export default app;