Source code for cadrumo.application.live.snapshot_identity
"""The one rule for deriving a live capture's snapshot identity.A capture's snapshot id is the digest of its canonical JSON, so two capturescarrying the same facts get the same id and a changed fact gets a new one. Twocapture modules each stated that rule for their own type; stated twice, a changeto what "canonical" means would have had to be made twice to keep ids stable."""from__future__importannotationsfrompydanticimportBaseModelfrom...core.hashingimportsha256_hex__all__=["derive_snapshot_id"]
[docs]defderive_snapshot_id(capture:BaseModel)->str:"""Return the snapshot identity of ``capture`` as the digest of its canonical JSON. Typed on the model base rather than on each capture, because the rule is about the serialisation and not about which capture is being serialised. """returnsha256_hex(capture.model_dump_json().encode("utf-8"))