BOARD

tcmts.cli.test.e2e.traces.BOARD · #opgmtkpj · term · runs anywhere

export const BOARD = `// tcm: namespace board
import { enqueue, table } from "#codebase/lib/server";

export const posts = table<{ text: string }>("posts");
export async function welcome(text: string): Promise<void> {
  await posts.count();
}
export async function add(text: string): Promise<string> {
  const id = await posts.insert({ text });
  enqueue(welcome, text);
  return id;
}
export async function list(): Promise<string[]> {
  return (await posts.find()).map((r) => r.value.text);
}
export async function crash(): Promise<void> {
  await posts.count();
  throw new Error("kaboom");
}
export async function main() {
  const b = document.createElement("button");
  b.onclick = async () => console.log(await add("x"), await list(), await crash());
  document.body.append(b);
}
`

used by