graflo.architecture.evolution.codec¶
(De)serialization for contract operations.
The op models are already pydantic under an op-discriminated union, but the
union was only ever used as a type annotation: there was no way to load a
heterogeneous list of ops from YAML, so change sets could not be stored,
transported or replayed. This module closes that gap.
RevisionOp is ManifestOp minus
:class:~graflo.architecture.evolution.ops.MergeManifestsOp, which is binary
(two manifests in, one out) and is rejected by the unary dispatcher anyway. A
revision applies to exactly one manifest, so merge is not a revision op.
Attributes¶
RevisionOp = Annotated[RemoveVerticesOp | AddResourceTransformsOp | EnsureExtractedFieldsOp | AddResourcesOp | RemoveResourcesOp | AddVerticesOp | AddEdgesOp | RetargetEdgesOp | AddSecondaryIdentitiesOp | RemoveSecondaryIdentitiesOp | ReplaceEdgeIdentitiesOp | ChangeFieldTypesOp | AddVertexIndexesOp | RemoveVertexIndexesOp | AddEdgeIndexesOp | RemoveEdgeIndexesOp | SetBindingsOp | SetDbProfileOp | SetEdgeDirectedOp | SetVertexSemanticsOp | SetVertexDescriptionsOp | SetEdgeSemanticsOp | SetFieldSemanticsOp | MergeVerticesOp | CanonicalizeOp | RenameVertexPropertiesOp | RemoveVertexPropertiesOp | AddVertexPropertiesOp | RenameVerticesOp | RenameRelationsOp | RenameResourcesOp | RemoveEdgesOp | MergeEdgesOp | RenameEdgePropertiesOp | RemoveEdgePropertiesOp | AddEdgePropertiesOp | DeclareEdgeInversesOp | RetractEdgeInversesOp | AddInverseEdgesOp | SetNativeInversesOp | SetInverseEmissionOp | ProjectManifestOp | ReplaceIdentityOp | SanitizeOp, PydanticField(discriminator='op')]
module-attribute
¶
__all__ = ['RevisionOp', 'is_revision_op', 'op_from_dict', 'op_to_dict', 'ops_from_dicts', 'ops_from_yaml', 'ops_to_dicts', 'ops_to_yaml_str']
module-attribute
¶
Classes¶
Functions:¶
is_revision_op(op)
¶
op_from_dict(payload)
¶
op_to_dict(op)
¶
Serialize one op to a payload that is guaranteed to load back.
Compact form first (defaults dropped), then verified by re-validating
it. That check is not paranoia: a nested discriminated union whose tag has
a default — IdentityTarget.mode is one — loses its tag under
exclude_defaults and becomes unloadable. Rather than special-casing
every such field, fall back to the full form whenever the compact one does
not reproduce the op.
A change set exists to be replayed exactly; silently emitting something that cannot be read back is the one failure this layer must not have.
Source code in graflo/architecture/evolution/codec.py
ops_from_dicts(payloads)
¶
ops_from_yaml(source)
¶
Load ops from a YAML file path, or from a YAML string.
Accepts either a bare list of op mappings or a mapping with an ops key.