1use crate::{
4 ExternalIdentifier, MediaRootId, MetadataProperty, ObjectRef, RepresentationId, ResourceId,
5 RevisionId,
6};
7
8#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
10#[non_exhaustive]
11pub enum ConflictKeyKind {
12 LocatorSet,
14 MetadataProperty,
16 DependencySet,
18 MediaRoot,
20 ExternalIdentifier,
22 ResourceFingerprint,
24 RepresentationFingerprint,
26 ResourceFileFacts,
28}
29
30impl ConflictKeyKind {
31 #[must_use]
33 pub const fn as_str(self) -> &'static str {
34 match self {
35 Self::LocatorSet => "locator_set",
36 Self::MetadataProperty => "metadata_property",
37 Self::DependencySet => "dependency_set",
38 Self::MediaRoot => "media_root",
39 Self::ExternalIdentifier => "external_identifier",
40 Self::ResourceFingerprint => "resource_fingerprint",
41 Self::RepresentationFingerprint => "representation_fingerprint",
42 Self::ResourceFileFacts => "resource_file_facts",
43 }
44 }
45}
46
47#[derive(Clone, Debug, Eq, Hash, PartialEq)]
49#[non_exhaustive]
50pub enum SemanticConflictKey {
51 ResourceFileFacts(ResourceId),
53 LocatorSet(ResourceId),
55 MetadataProperty {
57 target: ObjectRef,
59 property: MetadataProperty,
61 },
62 DependencySet(RepresentationId),
64 MediaRoot(MediaRootId),
66 ExternalIdentifier {
68 target: ObjectRef,
70 identifier: ExternalIdentifier,
72 },
73 ResourceFingerprint {
75 resource_id: ResourceId,
77 algorithm: String,
79 version: u16,
81 },
82 RepresentationFingerprint {
84 representation_id: RepresentationId,
86 algorithm: String,
88 version: u16,
90 },
91}
92
93impl SemanticConflictKey {
94 #[must_use]
96 pub const fn kind(&self) -> ConflictKeyKind {
97 match self {
98 Self::ResourceFileFacts(_) => ConflictKeyKind::ResourceFileFacts,
99 Self::LocatorSet(_) => ConflictKeyKind::LocatorSet,
100 Self::MetadataProperty { .. } => ConflictKeyKind::MetadataProperty,
101 Self::DependencySet(_) => ConflictKeyKind::DependencySet,
102 Self::MediaRoot(_) => ConflictKeyKind::MediaRoot,
103 Self::ExternalIdentifier { .. } => ConflictKeyKind::ExternalIdentifier,
104 Self::ResourceFingerprint { .. } => ConflictKeyKind::ResourceFingerprint,
105 Self::RepresentationFingerprint { .. } => ConflictKeyKind::RepresentationFingerprint,
106 }
107 }
108}
109
110#[derive(Clone, Debug, Eq, PartialEq)]
112pub struct TransactionConflict {
113 key: SemanticConflictKey,
114 base_revision: Option<RevisionId>,
115 base_sequence: u64,
116 superseding_revision: RevisionId,
117 superseding_sequence: u64,
118}
119
120impl TransactionConflict {
121 #[doc(hidden)]
123 #[must_use]
124 pub const fn new(
125 key: SemanticConflictKey,
126 base_revision: Option<RevisionId>,
127 base_sequence: u64,
128 superseding_revision: RevisionId,
129 superseding_sequence: u64,
130 ) -> Self {
131 Self {
132 key,
133 base_revision,
134 base_sequence,
135 superseding_revision,
136 superseding_sequence,
137 }
138 }
139
140 #[must_use]
142 pub const fn key(&self) -> &SemanticConflictKey {
143 &self.key
144 }
145
146 #[must_use]
148 pub const fn base_revision(&self) -> Option<RevisionId> {
149 self.base_revision
150 }
151
152 #[must_use]
154 pub const fn base_sequence(&self) -> u64 {
155 self.base_sequence
156 }
157
158 #[must_use]
160 pub const fn superseding_revision(&self) -> RevisionId {
161 self.superseding_revision
162 }
163
164 #[must_use]
166 pub const fn superseding_sequence(&self) -> u64 {
167 self.superseding_sequence
168 }
169}
170
171#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
173#[non_exhaustive]
174pub enum ConcurrencyClassification {
175 Merge,
177 Conflict,
179 ExistingGuard,
181 OperationDependent,
183}