SHOP_CALLS

tcmts.cli.test.e2e.traces.SHOP_CALLS · #lm2f3lsp · term · runs anywhere

export const SHOP_CALLS = `// tcm: namespace shop
import { table } from "#codebase/lib/server";

export const items = table<{ name: string }>("items");
export function label(name: string): string {
  return name.toUpperCase();
}
export function order(names: string[]): string[] {
  return [...names].sort().map(label);
}
export async function names(): Promise<string[]> {
  return (await items.find()).map((r) => r.value.name);
}
export async function add(name: string): Promise<string> {
  return items.insert({ name });
}
export async function list(): Promise<string[]> {
  // (it uses the table itself, so it runs on the server, calling names there rather than across the network)
  if (!(await items.count())) return [];
  return order(await names());
}
export async function sourceOfLabel(): Promise<string> {
  await items.count();
  return \`\${label}\`;
}
export async function main() {
  await add("x");
  document.body.textContent = (await list()).join() + (await sourceOfLabel());
}
`

used by