|
9 | 9 | """ |
10 | 10 |
|
11 | 11 | from datetime import datetime |
12 | | -from typing import List, Optional |
| 12 | +from enum import Enum |
| 13 | +from typing import Annotated, Any, List, Literal, Optional, Union |
13 | 14 | import uuid |
14 | 15 | from pydantic import BaseModel, Field |
15 | 16 |
|
@@ -62,24 +63,138 @@ class Observation(BaseModel): |
62 | 63 | ) |
63 | 64 |
|
64 | 65 |
|
65 | | -class KGChanges(BaseModel): |
| 66 | +class KGChangesType(Enum): |
66 | 67 | """ |
67 | | - KG changes model. |
| 68 | + KG changes type. |
68 | 69 | """ |
69 | 70 |
|
70 | | - id: str = Field(default_factory=lambda: str(uuid.uuid4())) |
| 71 | + RELATIONSHIP_CREATED = "relationship_created" |
| 72 | + RELATIONSHIP_DEPRECATED = "relationship_deprecated" |
| 73 | + NODE_PROPERTIES_UPDATED = "node_properties_updated" |
| 74 | + RELATIONSHIP_PROPERTIES_UPDATED = "relationship_properties_updated" |
| 75 | + |
| 76 | + |
| 77 | +class PartialNode(BaseModel): |
| 78 | + """ |
| 79 | + Partial node model. |
| 80 | + """ |
71 | 81 |
|
72 | | - node_ids: Optional[List[str]] = Field( |
73 | | - default=None, description="The id of the node that was changed." |
| 82 | + uuid: str = Field(description="The id of the node.") |
| 83 | + name: str = Field(description="The name of the node.") |
| 84 | + labels: List[str] = Field(description="The labels of the node.") |
| 85 | + description: Optional[str] = Field(description="The description of the node.") |
| 86 | + properties: dict = Field(description="The properties of the node.") |
| 87 | + |
| 88 | + |
| 89 | +class PartialPredicate(BaseModel): |
| 90 | + """ |
| 91 | + Partial relationship model. |
| 92 | + """ |
| 93 | + |
| 94 | + uuid: str = Field(description="The id of the relationship.") |
| 95 | + name: str = Field(description="The name of the relationship.") |
| 96 | + description: Optional[str] = Field( |
| 97 | + description="The description of the relationship." |
| 98 | + ) |
| 99 | + properties: Optional[dict] = Field( |
| 100 | + default=None, description="The properties of the relationship." |
| 101 | + ) |
| 102 | + |
| 103 | + |
| 104 | +class KGChangeLogRelationshipCreated(BaseModel): |
| 105 | + """ |
| 106 | + KG change log relationship created model. |
| 107 | + """ |
| 108 | + |
| 109 | + type: Literal[KGChangesType.RELATIONSHIP_CREATED] = Field( |
| 110 | + default=KGChangesType.RELATIONSHIP_CREATED, |
| 111 | + description="The type of the change.", |
| 112 | + ) |
| 113 | + subject: PartialNode = Field(description="The subject of the relationship.") |
| 114 | + predicate: PartialPredicate = Field( |
| 115 | + description="The predicate of the relationship." |
| 116 | + ) |
| 117 | + object: PartialNode = Field(description="The object of the relationship.") |
| 118 | + |
| 119 | + |
| 120 | +class KGChangeLogRelationshipDeprecated(BaseModel): |
| 121 | + """ |
| 122 | + KG change log relationship deprecated model. |
| 123 | + """ |
| 124 | + |
| 125 | + type: Literal[KGChangesType.RELATIONSHIP_DEPRECATED] = Field( |
| 126 | + default=KGChangesType.RELATIONSHIP_DEPRECATED, |
| 127 | + description="The type of the change.", |
| 128 | + ) |
| 129 | + subject: PartialNode = Field(description="The subject of the relationship.") |
| 130 | + predicate: PartialPredicate = Field( |
| 131 | + description="The predicate of the relationship." |
74 | 132 | ) |
75 | | - predicate_id: Optional[str] = Field( |
76 | | - default=None, description="The id of the predicate that was changed." |
| 133 | + object: PartialNode = Field(description="The object of the relationship.") |
| 134 | + new_predicate: Optional[PartialPredicate] = Field( |
| 135 | + description="The new predicate of the relationship." |
77 | 136 | ) |
78 | 137 |
|
79 | | - changelog: List[dict] = Field(description="The changelog of the changes.") |
80 | | - date: datetime = Field( |
| 138 | + |
| 139 | +class KGChangeLogPredicateUpdatedProperty(BaseModel): |
| 140 | + """ |
| 141 | + KG change log relationship updated property model. |
| 142 | + """ |
| 143 | + |
| 144 | + property: str = Field(description="The property that was updated.") |
| 145 | + previous_value: Any = Field(description="The previous value of the property.") |
| 146 | + new_value: Any = Field(description="The new value of the property.") |
| 147 | + |
| 148 | + |
| 149 | +class KGChangeLogNodePropertiesUpdated(BaseModel): |
| 150 | + """ |
| 151 | + KG change log node properties updated model. |
| 152 | + """ |
| 153 | + |
| 154 | + type: Literal[KGChangesType.NODE_PROPERTIES_UPDATED] = Field( |
| 155 | + default=KGChangesType.NODE_PROPERTIES_UPDATED, |
| 156 | + description="The type of the change.", |
| 157 | + ) |
| 158 | + node: PartialNode = Field(description="The node that was updated.") |
| 159 | + properties: List[KGChangeLogPredicateUpdatedProperty] = Field( |
| 160 | + description="The properties that were updated." |
| 161 | + ) |
| 162 | + |
| 163 | + |
| 164 | +class KGChangeLogPredicatePropertiesUpdated(BaseModel): |
| 165 | + """ |
| 166 | + KG change log relationship properties updated model. |
| 167 | + """ |
| 168 | + |
| 169 | + type: Literal[KGChangesType.RELATIONSHIP_PROPERTIES_UPDATED] = Field( |
| 170 | + default=KGChangesType.RELATIONSHIP_PROPERTIES_UPDATED, |
| 171 | + description="The type of the change.", |
| 172 | + ) |
| 173 | + predicate: PartialPredicate = Field(description="The predicate that was updated.") |
| 174 | + properties: List[KGChangeLogPredicateUpdatedProperty] = Field( |
| 175 | + description="The properties that were updated." |
| 176 | + ) |
| 177 | + |
| 178 | + |
| 179 | +class KGChanges(BaseModel): |
| 180 | + """ |
| 181 | + KG changes model. |
| 182 | + """ |
| 183 | + |
| 184 | + id: str = Field(default_factory=lambda: str(uuid.uuid4())) |
| 185 | + type: KGChangesType = Field(description="The type of the changes.") |
| 186 | + change: Annotated[ |
| 187 | + Union[ |
| 188 | + KGChangeLogRelationshipCreated, |
| 189 | + KGChangeLogRelationshipDeprecated, |
| 190 | + KGChangeLogNodePropertiesUpdated, |
| 191 | + KGChangeLogPredicatePropertiesUpdated, |
| 192 | + ], |
| 193 | + Field(discriminator="type"), |
| 194 | + ] = Field(description="The change data, discriminated by type.") |
| 195 | + timestamp: datetime = Field( |
81 | 196 | default_factory=datetime.now, |
82 | | - description="The date and time the changes were made.", |
| 197 | + description="The timestamp of the changes.", |
83 | 198 | ) |
84 | 199 |
|
85 | 200 |
|
|
0 commit comments