import { packageStorage } from 'kody:runtime' export type Item = { id: string; text: string; createdAt: string } function keyFor(userId: string) { return `items:${userId}` } /** Each signed-in person gets their own list in package storage. */ export async function listItems(userId: string): Promise> { const stored = await packageStorage().get(keyFor(userId)) return Array.isArray(stored) ? (stored as Array) : [] } export async function addItem(userId: string, text: string) { const item: Item = { id: crypto.randomUUID(), text, createdAt: new Date().toISOString(), } await packageStorage().set(keyFor(userId), [item, ...(await listItems(userId))]) return item } export async function deleteItem(userId: string, id: string) { const items = await listItems(userId) await packageStorage().set( keyFor(userId), items.filter((item) => item.id !== id), ) }