import { HelioDB } from "@heliodb/client";
import { heliodb } from "@heliodb/contract";
import { z } from "zod";
const contract = {
chat: heliodb.resource("chat/{roomId}").events({
message: z.object({ text: z.string(), userId: z.string() }),
}),
} as const;
const client = new HelioDB({
url: "ws://localhost:8080/ws",
contract,
token: "<your-token>",
namespace: "default",
});
const room = client.resources.chat({ roomId: "general" });
// Log events
room.log({ type: "message", data: { text: "hello", userId: "alice" } });
// Subscribe: history first, then live
const subscription = await room.subscribe();
for await (const event of subscription) {
console.log(event.id, event.type, event.data);
}