| 101 | |
| 102 | # --- 6. change detection: emit only meaningful changes (powers monitoring/alerts) |
| 103 | def diff_record(old: dict | None, new: dict, watch: list[str]) -> dict: |
| 104 | if old is None: |
| 105 | return {"type": "new", "fields": {f: new.get(f) for f in watch}} |
| 106 | changed = {f: {"from": old.get(f), "to": new.get(f)} for f in watch if old.get(f) != new.get(f)} |
| 107 | return {"type": "changed", "fields": changed} if changed else {"type": "unchanged"} |
| 108 | |
| 109 | |
| 110 | # --------------------------------------------------------------------------- |