- 3.1observeWhat does this depend on? Snapshotted at plan time, re-checked before apply.
- 3.2checkBusiness rules. A violation denies the plan before a human is bothered.
- 3.3previewThe exact effects, in words a person can sign.
- 3.4executeThe change, with a stable idempotency key to pass downstream.
- 3.5verifyProof against the real system. Not optional.
- 3.6compensateThe way back. Required unless you declare the action irreversible.
export const setReorderPoint = defineAction({
name: "set_reorder_point",
description: "Change the reorder point of an inventory item.",
reversibility: "reversible",
input: t.object({ sku: t.string(), reorderPoint: t.integer({ min: 0 }) }),
observe: ({ sku }) => erp.getItem(sku),
check: (_, item) => (item ? [] : ["item does not exist"]),
preview: ({ sku, reorderPoint }, item) =>
[{ target: `item:${sku}`, op: "update", before: item.reorderPoint, after: reorderPoint }],
execute: (i, { idempotencyKey }) => erp.update(i, idempotencyKey),
verify: (i) => erp.getItem(i.sku)?.reorderPoint === i.reorderPoint,
compensate: (i, _, { before }) => erp.update({ ...i, reorderPoint: before.reorderPoint }),
});