keepStar
uses tcmts.hub.stars, which uses tcmts.server.table, which uses tcmts.server.Table, which uses #tcm/host (database)
Keep a star's row: the one at its URI replaced, else a new one, in one transaction. Jetstream's event and the visitor's own restar can both be keeping the same star at once, and the URI is unique.
import { stars } from "#codebase/tcmts/hub"; import type { HubStar } from "#codebase/tcmts/hub"; import { transaction } from "#codebase/tcmts/server"; export const keepStar = (row: HubStar): Promise<void> => transaction(async () => { const had = await stars.findOne({ uri: row.uri }); if (had) await stars.put(had.id, row); else await stars.insert(row); })