graflo.architecture.schema.anchor¶
What a traversal may be anchored on: a complete key, never a property match.
An anchor names one vertex. A key contract
(:func:~graflo.architecture.schema.key_contract.key_contract) says which field
sets do that, so an anchor is one of:
| Form | Given as | Resolved by |
|---|---|---|
bare |
a scalar, for a type whose primary identity is one field | nothing: it is that field's value |
identity |
a mapping naming exactly the primary identity fields | nothing |
key_set |
a mapping naming exactly one source field set of a derived key | the digest |
alternate |
a mapping naming exactly one secondary identity | a lookup, which may find one, several or none |
Anything else is a lookup by description, not an anchor: a mapping on a field that is no key could name many vertices, and walking from an arbitrary one of them answers a question nobody asked. Such a mapping is refused, as is one that names only part of a key set.
:func:classify_anchor is pure; :func:graflo.hq.anchor.anchor_identity runs
the lookup an alternate anchor needs.
Attributes¶
AnchorForm = Literal['bare', 'identity', 'key_set', 'alternate']
module-attribute
¶
Classes¶
AnchorAmbiguousError
¶
Bases: AnchorKeyError
A secondary identity anchor names several vertices.
Source code in graflo/architecture/schema/anchor.py
AnchorIncompleteError
¶
Bases: AnchorKeyError
The anchor names part of a key, or a key with an empty value.
Source code in graflo/architecture/schema/anchor.py
AnchorKeyError
¶
Bases: ValueError
An anchor that does not name exactly one vertex.
code classifies the refusal without parsing its message; seed is the
position of the traversal seed that carried it, when there was one.
Source code in graflo/architecture/schema/anchor.py
AnchorNotAKeyError
¶
Bases: AnchorKeyError
The anchor mapping names fields that form no key of the type.
Source code in graflo/architecture/schema/anchor.py
AnchorUnmatchedError
¶
Bases: AnchorKeyError
A secondary identity anchor names no vertex the reader can see.
Source code in graflo/architecture/schema/anchor.py
Functions:¶
check_anchor_shape(vertex_type, key)
¶
Refuse an anchor that is neither a scalar nor a mapping of scalars.
Raises:
| Type | Description |
|---|---|
AnchorNotAKeyError
|
a container value, or a mapping key that is not text. |
AnchorIncompleteError
|
an empty mapping, or an empty value. |
Source code in graflo/architecture/schema/anchor.py
classify_anchor(contract, key)
¶
Which form key takes under contract, and the key set it names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contract
|
KeyContract
|
Key contract of the anchor's type. |
required |
key
|
Any
|
A scalar or a mapping of field names to scalars. |
required |
Returns:
| Type | Description |
|---|---|
tuple[AnchorForm, KeySet | None]
|
The form, and for |
Raises:
| Type | Description |
|---|---|
AnchorNotAKeyError
|
the mapping names fields that form no key. |
AnchorIncompleteError
|
a scalar for a composite primary identity, part of a key set, or an empty value. |