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() }),
}),
};
const client = new HelioDB({
url: "ws://localhost:8080/ws",
contract,
token: "<dev token>",
namespace: "default",
subject: "chat-ui",
});
const room = client.resources.chat({ roomId: "general" });
await room.log({ type: "message", data: { text: "hello", userId: "alice" } });
// Fire-and-forget for streaming; pass durable: true or await room.flush() when you need to block
const sub = await room.subscribe();
for await (const event of sub) console.log(event.id, event.type, event.data);