// `orderChanges` — a post-commit subscriber on the `orders` table. // // Fires AFTER commit (the row IS written), best-effort + fire-and-forget // (a throw logs and the next event still arrives; it can't back-pressure // the change stream). Use it for reactions that aren't part of the // write transaction — notify a fulfillment desk, mirror to a search // index, bump a metric. `ctx.store` is there when the reaction needs to // read or write; it runs as the SYSTEM subject (no request, so no // tenant), which means a write to a `tenant()` table has to carry its // `tenantId` explicitly — take it off the row that changed. // // For crash-safe multi-step reactions, use a `*.reaction.tsx`: a // subscriber has no workflow handle, on purpose, because it is // best-effort and a workflow kickoff should not be. // // `on: 'any'` matches insert / update / delete. `event.new` is present // on insert + update (null on delete); `event.old` on update + delete // (null on insert). import { defineSubscriber } from '@voltro/runtime' export default defineSubscriber({ table: 'orders', on: 'any', handler: async (event, ctx) => { const row = (event.new ?? event.old) as { id?: string; status?: string } | null ctx.log.info('order changed', { op: event.op, id: row?.id, status: row?.status, }) }, })