Add generic object reference models
This commit is contained in:
@@ -59,6 +59,57 @@ class Endpoint:
|
||||
return f"{self.plugin}://{self.address}"
|
||||
|
||||
|
||||
@dataclass(frozen=True, order=True)
|
||||
class ObjectReference:
|
||||
relation: str
|
||||
object_type: str
|
||||
local_key: str | None = None
|
||||
logical_key: str | None = None
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
relation = self.relation.strip().lower()
|
||||
object_type = self.object_type.strip().lower()
|
||||
|
||||
if not relation:
|
||||
raise ValueError("Object reference relation cannot be empty")
|
||||
if not object_type:
|
||||
raise ValueError(
|
||||
"Object reference object_type cannot be empty"
|
||||
)
|
||||
if (self.local_key is None) == (self.logical_key is None):
|
||||
raise ValueError(
|
||||
"Object reference requires exactly one of "
|
||||
"local_key or logical_key"
|
||||
)
|
||||
|
||||
object.__setattr__(self, "relation", relation)
|
||||
object.__setattr__(self, "object_type", object_type)
|
||||
|
||||
if self.local_key is not None:
|
||||
if not isinstance(self.local_key, str):
|
||||
raise ValueError(
|
||||
"Object reference local_key must be a string"
|
||||
)
|
||||
local_key = self.local_key.strip()
|
||||
if not local_key:
|
||||
raise ValueError(
|
||||
"Object reference local_key cannot be empty"
|
||||
)
|
||||
object.__setattr__(self, "local_key", local_key)
|
||||
|
||||
if self.logical_key is not None:
|
||||
if not isinstance(self.logical_key, str):
|
||||
raise ValueError(
|
||||
"Object reference logical_key must be a string"
|
||||
)
|
||||
logical_key = self.logical_key.strip()
|
||||
if not logical_key:
|
||||
raise ValueError(
|
||||
"Object reference logical_key cannot be empty"
|
||||
)
|
||||
object.__setattr__(self, "logical_key", logical_key)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class DiscoveredObject:
|
||||
object_type: str
|
||||
@@ -74,6 +125,25 @@ class NormalizedObject:
|
||||
local_key: str | None = None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ApplyResult:
|
||||
object: NormalizedObject
|
||||
detail: str | None = None
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
if self.object.local_key is None:
|
||||
raise ValueError(
|
||||
"Applied object requires an endpoint-local key"
|
||||
)
|
||||
if self.detail is not None:
|
||||
detail = self.detail.strip()
|
||||
object.__setattr__(
|
||||
self,
|
||||
"detail",
|
||||
detail or None,
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Observation:
|
||||
endpoint_id: str
|
||||
|
||||
Reference in New Issue
Block a user