postproject_core/storage.rs
1//! Domain-shaped contracts implemented by persistence backends.
2
3use std::time::Duration;
4
5use crate::{
6 Activity, ActivityOutputQuery, AgentIdentity, ArtifactEvaluation, ArtifactEvaluationLimits,
7 ArtifactReproducibilityReport, Asset, AssetId, CommitReceipt, DecisionBase, Dependency,
8 DependencyQueryLimits, DependencyQueryMatch, DependencySet, DependencyTarget,
9 ExternalIdentifier, FileFacts, FilteredRevisionPage, IdentifierScheme, Job, JobFailure, JobId,
10 JobQuery, KnownMediaMatch, Locator, LocatorIdentity, MediaRoot, MetadataAssertion,
11 MetadataMatch, MetadataProperty, MetadataQuery, MetadataValue, ObjectRef, OriginalMediaImport,
12 Production, ProductionReadSession, ProvenanceQueryLimits, ProvenanceQueryMatch, QueryPage,
13 QueryPageRequest, RegenerationJobPlan, Representation, RepresentationFingerprint,
14 RepresentationId, RepresentationImport, Resource, ResourceFingerprint, ResourceId, Result,
15 Revision, RevisionContext, RevisionEvent, RevisionEventFilter, RevisionId, StaleArtifactQuery,
16 ToolIdentity, TransactionId, TransactionState,
17};
18
19/// Read operations required from a production persistence backend.
20///
21/// The contract returns domain values and deliberately contains no generic CRUD,
22/// query language, connection, or database-row concepts.
23pub trait ProductionRead {
24 /// Returns the loaded production identity and header metadata.
25 fn production(&self) -> &Production;
26
27 /// Queries a bounded page of roots in priority/identity order.
28 ///
29 /// Live readers load current facts; retained sessions use their pinned view.
30 ///
31 /// # Errors
32 ///
33 /// Returns a domain error for an invalid cursor or unreadable stored data.
34 fn media_roots_page(&self, page: &QueryPageRequest) -> Result<QueryPage<MediaRoot>>;
35
36 /// Loads current roots up to [`crate::MAX_QUERY_PAGE_SIZE`].
37 ///
38 /// # Errors
39 ///
40 /// Returns an unsupported error if the result exceeds that cap; callers
41 /// needing more roots use pages. Storage and cursor errors propagate.
42 fn media_roots(&self) -> Result<Vec<MediaRoot>> {
43 let page =
44 self.media_roots_page(&QueryPageRequest::new(crate::MAX_QUERY_PAGE_SIZE, None)?)?;
45 if page.next_cursor().is_some() {
46 return Err(crate::Error::new(
47 crate::ErrorKind::Unsupported,
48 "media-root collection exceeds 1000 roots; use bounded pages",
49 ));
50 }
51 Ok(page.into_items())
52 }
53
54 /// Loads all assets in deterministic order.
55 ///
56 /// Complete-list convenience is capped at 1000; use pages for larger results.
57 /// It returns `Unsupported` rather than truncating the collection.
58 ///
59 /// # Errors
60 ///
61 /// Returns a storage-domain error when persisted data cannot be read or
62 /// decoded safely.
63 fn assets(&self) -> Result<Vec<Asset>>;
64
65 /// Queries one bounded page of assets in creation/identity order.
66 ///
67 /// # Errors
68 ///
69 /// Returns a domain error for an invalid cursor or unreadable storage.
70 fn assets_page(&self, page: &QueryPageRequest) -> Result<QueryPage<Asset>>;
71
72 /// Loads one asset by identity.
73 ///
74 /// # Errors
75 ///
76 /// Returns a not-found error when the asset is absent, or a storage-domain
77 /// error when persisted data cannot be read or decoded safely.
78 fn asset(&self, asset_id: AssetId) -> Result<Asset>;
79
80 /// Loads one representation, with its structure and fingerprints, by
81 /// identity.
82 ///
83 /// # Errors
84 ///
85 /// Returns a not-found error when the representation is absent, or a
86 /// storage-domain error when persisted data cannot be decoded safely.
87 fn representation(&self, representation_id: RepresentationId) -> Result<Representation>;
88
89 /// Loads every representation belonging to an asset in deterministic order.
90 ///
91 /// Complete-list convenience is capped at 1000; use pages for larger results.
92 /// It returns `Unsupported` rather than truncating the collection.
93 ///
94 /// # Errors
95 ///
96 /// Returns a storage-domain error when persisted data cannot be read or
97 /// decoded safely.
98 fn representations(&self, asset_id: AssetId) -> Result<Vec<Representation>>;
99
100 /// Queries one bounded page of representations belonging to an asset.
101 ///
102 /// # Errors
103 ///
104 /// Returns a domain error when the asset is absent, the cursor is invalid,
105 /// or persisted representation data cannot be decoded safely.
106 fn representations_page(
107 &self,
108 asset_id: AssetId,
109 page: &QueryPageRequest,
110 ) -> Result<QueryPage<Representation>>;
111
112 /// Loads resources used by a representation in structural order.
113 ///
114 /// Complete-list convenience is capped at 1000; use pages for larger results.
115 /// It returns `Unsupported` rather than truncating the collection.
116 ///
117 /// # Errors
118 ///
119 /// Returns a storage-domain error when persisted data cannot be read or
120 /// decoded safely.
121 fn resources(&self, representation_id: RepresentationId) -> Result<Vec<Resource>>;
122
123 /// Queries one bounded page of resources in structural order.
124 ///
125 /// # Errors
126 ///
127 /// Returns a domain error when the representation is absent, the cursor is
128 /// invalid, or persisted resource data cannot be decoded safely.
129 fn resources_page(
130 &self,
131 representation_id: RepresentationId,
132 page: &QueryPageRequest,
133 ) -> Result<QueryPage<Resource>>;
134
135 /// Loads every known locator belonging to a resource.
136 ///
137 /// Complete-list convenience is capped at 1000; use pages for larger results.
138 /// It returns `Unsupported` rather than truncating the collection.
139 ///
140 /// # Errors
141 ///
142 /// Returns a storage-domain error when persisted data cannot be read or
143 /// decoded safely.
144 fn locators(&self, resource_id: ResourceId) -> Result<Vec<Locator>>;
145
146 /// Queries one bounded page of locators belonging to a resource.
147 ///
148 /// # Errors
149 ///
150 /// Returns a domain error when the resource is absent, the cursor is
151 /// invalid, or persisted locator data cannot be decoded safely.
152 fn locators_page(
153 &self,
154 resource_id: ResourceId,
155 page: &QueryPageRequest,
156 ) -> Result<QueryPage<Locator>>;
157
158 /// Finds current resources and their owning production objects by exact
159 /// canonical locator identity.
160 ///
161 /// The operation is read-only. It returns every candidate and never adopts,
162 /// relinks, or merges media implicitly.
163 ///
164 /// # Errors
165 ///
166 /// Returns a domain error for an invalid cursor or unreadable storage.
167 fn find_known_media_by_locator(
168 &self,
169 locator: &LocatorIdentity,
170 page: &QueryPageRequest,
171 ) -> Result<QueryPage<KnownMediaMatch>>;
172
173 /// Finds resources whose current effective fingerprint exactly matches,
174 /// together with every owning representation and asset.
175 ///
176 /// Historical fingerprint observations are not searched. The operation is
177 /// read-only and returns every candidate without inferring logical identity.
178 ///
179 /// # Errors
180 ///
181 /// Returns a domain error for an invalid cursor or unreadable storage.
182 fn find_known_media_by_fingerprint(
183 &self,
184 fingerprint: &ResourceFingerprint,
185 page: &QueryPageRequest,
186 ) -> Result<QueryPage<KnownMediaMatch>>;
187
188 /// Queries representations with a locator recorded under a logical root.
189 ///
190 /// # Errors
191 ///
192 /// Returns a domain error when the root is absent, the cursor is invalid,
193 /// or persisted representation data cannot be decoded safely.
194 fn representations_under_media_root(
195 &self,
196 root_name: &str,
197 page: &QueryPageRequest,
198 ) -> Result<QueryPage<Representation>>;
199
200 /// Queries representations that use a resource, in identity order.
201 ///
202 /// A resource is usually used by one representation, but the model allows
203 /// several representations to share it, so the result is a bounded page.
204 ///
205 /// # Errors
206 ///
207 /// Returns a domain error when the resource is absent, the cursor is
208 /// invalid, or persisted representation data cannot be decoded safely.
209 fn representations_using_resource(
210 &self,
211 resource_id: ResourceId,
212 page: &QueryPageRequest,
213 ) -> Result<QueryPage<Representation>>;
214
215 /// Queries representations whose required resources have no active locator.
216 ///
217 /// # Errors
218 ///
219 /// Returns a domain error for an invalid cursor or unreadable storage.
220 fn unresolved_media(&self, page: &QueryPageRequest) -> Result<QueryPage<RepresentationId>>;
221
222 /// Loads external identifiers attached to `target` in deterministic order.
223 ///
224 /// # Errors
225 ///
226 /// Returns a storage-domain error when persisted data cannot be read or
227 /// decoded safely, or when the target kind is not supported.
228 fn external_identifiers(&self, target: ObjectRef) -> Result<Vec<ExternalIdentifier>>;
229
230 /// Finds objects carrying the exact external scheme and value.
231 ///
232 /// A `qualifier` restricts matches to identifiers with exactly that
233 /// qualifier; `None` matches any qualifier, including none.
234 ///
235 /// # Errors
236 ///
237 /// Returns a domain error when the lookup value or qualifier is invalid
238 /// or persisted data cannot be decoded safely.
239 fn find_by_external_identifier(
240 &self,
241 scheme: &IdentifierScheme,
242 value: &str,
243 qualifier: Option<&str>,
244 ) -> Result<Vec<ObjectRef>>;
245
246 /// Loads all metadata assertions attached to `target` in deterministic order.
247 ///
248 /// # Errors
249 ///
250 /// Returns a domain error when the target kind is unsupported or persisted
251 /// data cannot be decoded safely.
252 fn metadata(&self, target: ObjectRef) -> Result<Vec<MetadataAssertion>>;
253
254 /// Loads every ordered value for one property on `target`.
255 ///
256 /// # Errors
257 ///
258 /// Returns a domain error when the target kind is unsupported or persisted
259 /// data cannot be decoded safely.
260 fn metadata_values(
261 &self,
262 target: ObjectRef,
263 property: &MetadataProperty,
264 ) -> Result<Vec<MetadataValue>>;
265
266 /// Finds every object carrying `property`, preserving value repetition.
267 ///
268 /// # Errors
269 ///
270 /// Returns a domain error when persisted data cannot be decoded safely.
271 fn query_by_metadata_property(&self, property: &MetadataProperty)
272 -> Result<Vec<MetadataMatch>>;
273
274 /// Queries one bounded page of objects carrying a metadata property.
275 ///
276 /// # Errors
277 ///
278 /// Returns a domain error for an invalid cursor, invalid predicate, or
279 /// malformed persisted metadata.
280 fn metadata_query(
281 &self,
282 query: &MetadataQuery,
283 page: &QueryPageRequest,
284 ) -> Result<QueryPage<MetadataMatch>>;
285
286 /// Loads all production activities in deterministic identity order.
287 ///
288 /// # Errors
289 ///
290 /// Returns a storage-domain error when persisted activity data cannot be
291 /// read or decoded safely.
292 fn activities(&self) -> Result<Vec<Activity>>;
293
294 /// Loads activities that produce `representation_id`.
295 ///
296 /// # Errors
297 ///
298 /// Returns a domain error when the representation is absent or persisted
299 /// activity data cannot be read safely.
300 fn activities_producing(&self, representation_id: RepresentationId) -> Result<Vec<Activity>>;
301
302 /// Loads activities that consume `representation_id`.
303 ///
304 /// # Errors
305 ///
306 /// Returns a domain error when the representation is absent or persisted
307 /// activity data cannot be read safely.
308 fn activities_consuming(&self, representation_id: RepresentationId) -> Result<Vec<Activity>>;
309
310 /// Queries activity outputs selected by exact activity or tool identity.
311 ///
312 /// # Errors
313 ///
314 /// Returns a domain error for an invalid cursor or malformed persisted IDs.
315 fn activity_outputs(
316 &self,
317 query: &ActivityOutputQuery,
318 page: &QueryPageRequest,
319 ) -> Result<QueryPage<RepresentationId>>;
320
321 /// Queries a bounded page of activities producing one representation.
322 ///
323 /// # Errors
324 ///
325 /// Returns a domain error when the representation is absent, the cursor is
326 /// invalid, or activity data cannot be decoded safely.
327 fn activities_producing_page(
328 &self,
329 representation_id: RepresentationId,
330 page: &QueryPageRequest,
331 ) -> Result<QueryPage<Activity>>;
332
333 /// Queries a bounded page of activities consuming one representation.
334 ///
335 /// # Errors
336 ///
337 /// Returns a domain error when the representation is absent, the cursor is
338 /// invalid, or activity data cannot be decoded safely.
339 fn activities_consuming_page(
340 &self,
341 representation_id: RepresentationId,
342 page: &QueryPageRequest,
343 ) -> Result<QueryPage<Activity>>;
344
345 /// Returns every transitive provenance ancestor of `representation_id`.
346 ///
347 /// # Errors
348 ///
349 /// Returns a domain error when the representation is absent or persisted
350 /// provenance cannot be traversed safely.
351 fn ancestors(&self, representation_id: RepresentationId) -> Result<Vec<RepresentationId>>;
352
353 /// Returns every transitive provenance descendant of `representation_id`.
354 ///
355 /// # Errors
356 ///
357 /// Returns a domain error when the representation is absent or persisted
358 /// provenance cannot be traversed safely.
359 fn descendants(&self, representation_id: RepresentationId) -> Result<Vec<RepresentationId>>;
360
361 /// Queries bounded, shortest-depth provenance ancestors.
362 ///
363 /// # Errors
364 ///
365 /// Returns a domain error when the root is absent, the cursor is invalid,
366 /// or persisted provenance cannot be traversed safely.
367 fn ancestors_page(
368 &self,
369 representation_id: RepresentationId,
370 limits: ProvenanceQueryLimits,
371 page: &QueryPageRequest,
372 ) -> Result<QueryPage<ProvenanceQueryMatch>>;
373
374 /// Queries bounded, shortest-depth provenance descendants.
375 ///
376 /// # Errors
377 ///
378 /// Returns a domain error when the root is absent, the cursor is invalid,
379 /// or persisted provenance cannot be traversed safely.
380 fn descendants_page(
381 &self,
382 representation_id: RepresentationId,
383 limits: ProvenanceQueryLimits,
384 page: &QueryPageRequest,
385 ) -> Result<QueryPage<ProvenanceQueryMatch>>;
386
387 /// Loads the complete dependency observation for a representation.
388 ///
389 /// `None` means that no dependency set has been recorded. An empty set is
390 /// returned as `Some` and is distinct from missing knowledge.
391 ///
392 /// # Errors
393 ///
394 /// Returns a domain error when the representation is absent or persisted
395 /// dependency data cannot be decoded safely.
396 fn dependency_set(&self, representation_id: RepresentationId) -> Result<Option<DependencySet>>;
397
398 /// Queries direct or transitive dependency targets in stable key order.
399 ///
400 /// # Errors
401 ///
402 /// Returns a domain error when the source is absent, the cursor does not
403 /// belong to the query, or persisted dependencies cannot be decoded safely.
404 fn dependencies(
405 &self,
406 source: RepresentationId,
407 limits: DependencyQueryLimits,
408 page: &QueryPageRequest,
409 ) -> Result<QueryPage<DependencyQueryMatch>>;
410
411 /// Queries direct or transitive dependent representations in stable order.
412 ///
413 /// A representation target includes pinned references and floating asset
414 /// references recorded as resolved to that representation.
415 ///
416 /// # Errors
417 ///
418 /// Returns a domain error when the target is absent or persisted IDs cannot
419 /// be decoded safely.
420 fn dependents(
421 &self,
422 target: DependencyTarget,
423 limits: DependencyQueryLimits,
424 page: &QueryPageRequest,
425 ) -> Result<QueryPage<DependencyQueryMatch>>;
426
427 /// Evaluates whether an activity-produced representation still reflects
428 /// its recorded inputs and output snapshot.
429 ///
430 /// This operation reads production knowledge only and never resolves or
431 /// accesses media files.
432 ///
433 /// # Errors
434 ///
435 /// Returns a domain error when the target is absent, bounds are invalid,
436 /// or stored provenance cannot be decoded safely.
437 fn evaluate_artifact(
438 &self,
439 representation_id: RepresentationId,
440 limits: ArtifactEvaluationLimits,
441 ) -> Result<ArtifactEvaluation>;
442
443 /// Reports whether recorded production knowledge can reproduce an artifact.
444 ///
445 /// # Errors
446 ///
447 /// Returns a domain error when the target is absent or stored provenance
448 /// cannot be decoded safely.
449 fn artifact_reproducibility(
450 &self,
451 representation_id: RepresentationId,
452 ) -> Result<ArtifactReproducibilityReport>;
453
454 /// Queries representations currently evaluated as stale.
455 ///
456 /// # Errors
457 ///
458 /// Returns a domain error when the source is absent, the cursor is invalid,
459 /// or artifact knowledge cannot be evaluated safely.
460 fn stale_artifacts(
461 &self,
462 query: StaleArtifactQuery,
463 page: &QueryPageRequest,
464 ) -> Result<QueryPage<RepresentationId>>;
465
466 /// Queries durable jobs in stable identity order.
467 ///
468 /// # Errors
469 ///
470 /// Returns a storage-domain error when persisted job data cannot be read
471 /// or decoded safely.
472 fn jobs(&self, query: &JobQuery, page: &QueryPageRequest) -> Result<QueryPage<Job>>;
473
474 /// Loads one durable job by identity.
475 ///
476 /// # Errors
477 ///
478 /// Returns a not-found error when the job is absent, or a storage-domain
479 /// error when its persisted data cannot be decoded safely.
480 fn job(&self, job_id: JobId) -> Result<Job>;
481
482 /// Derives non-persisted job requests for existing artifacts.
483 ///
484 /// Each artifact must have exactly one producing activity. The plan copies
485 /// that activity's kind, distinct input representations, and typed metadata
486 /// parameters. The caller explicitly enqueues any returned plan.
487 ///
488 /// # Errors
489 ///
490 /// Returns a domain error when the request is excessive, an artifact is
491 /// absent, its producing activity is missing or ambiguous, or persisted
492 /// activity/metadata data cannot be decoded safely.
493 fn plan_regeneration(
494 &self,
495 representation_ids: &[RepresentationId],
496 ) -> Result<Vec<RegenerationJobPlan>>;
497
498 /// Returns the newest durable revision, or `None` for an empty journal.
499 ///
500 /// # Errors
501 ///
502 /// Returns a storage-domain error when persisted revision data is invalid.
503 fn latest_revision(&self) -> Result<Option<Revision>>;
504
505 /// Returns revisions after `sequence` in ascending order, capped by `limit`.
506 ///
507 /// # Errors
508 ///
509 /// Returns a domain error when `limit` is zero or excessive, or when
510 /// persisted revision data is invalid.
511 fn changes_since(&self, sequence: u64, limit: u32) -> Result<Vec<Revision>>;
512
513 /// Returns revisions after `sequence` that contain at least one event of
514 /// the filter's types, in ascending order, capped by `limit`.
515 ///
516 /// The page's through sequence is the cursor for the next filtered page;
517 /// every matching revision up to it is included.
518 ///
519 /// # Errors
520 ///
521 /// Returns a domain error when `limit` is zero or excessive, or when
522 /// persisted revision data is invalid.
523 fn changes_since_filtered(
524 &self,
525 sequence: u64,
526 filter: &RevisionEventFilter,
527 limit: u32,
528 ) -> Result<FilteredRevisionPage>;
529
530 /// Loads the semantic events for one revision in stable position order.
531 ///
532 /// # Errors
533 ///
534 /// Returns a domain error when the revision is absent or persisted event
535 /// data is invalid.
536 fn events_for_revision(&self, revision_id: RevisionId) -> Result<Vec<RevisionEvent>>;
537
538 /// Returns one bounded page of a revision's events in position order.
539 ///
540 /// Cursors belong to the revision, production and retained read view.
541 ///
542 /// # Errors
543 ///
544 /// Returns a domain error for an absent revision, an invalid cursor or
545 /// malformed persisted event data.
546 fn events_for_revision_page(
547 &self,
548 revision_id: RevisionId,
549 page: &QueryPageRequest,
550 ) -> Result<QueryPage<RevisionEvent>>;
551
552 /// Queries distinct metadata-capable objects touched after a revision.
553 ///
554 /// # Errors
555 ///
556 /// Returns a domain error for an invalid cursor or malformed journal data.
557 fn objects_changed_since(
558 &self,
559 sequence: u64,
560 page: &QueryPageRequest,
561 ) -> Result<QueryPage<ObjectRef>>;
562}
563
564/// Transactional mutation operations required from a persistence backend.
565pub trait ProductionStoreTransaction {
566 /// Backend-owned worker capability activated by this edit's commit.
567 type Lease: crate::JobLease;
568 /// Returns this transaction's stable identity.
569 fn id(&self) -> TransactionId;
570
571 /// Returns the current lifecycle state.
572 fn state(&self) -> TransactionState;
573
574 /// Sets the origin and message for the revision created on commit.
575 ///
576 /// # Errors
577 ///
578 /// Returns a domain error when the transaction is already closed.
579 fn set_revision_context(&mut self, context: RevisionContext) -> Result<()>;
580
581 /// Stages one prepared original-media aggregate atomically.
582 ///
583 /// # Errors
584 ///
585 /// Returns a domain error when the transaction is closed or persistence
586 /// rejects the aggregate.
587 fn import_original(&mut self, import: &OriginalMediaImport) -> Result<()>;
588
589 /// Stages a representation and its newly imported resources on an existing asset.
590 ///
591 /// # Errors
592 ///
593 /// Returns a domain error when the transaction is closed, the owning asset
594 /// does not exist, or persistence rejects the aggregate.
595 fn add_representation(&mut self, import: &RepresentationImport) -> Result<()>;
596
597 /// Stages an explicitly confirmed resource locator.
598 ///
599 /// # Errors
600 ///
601 /// Returns a domain error when the transaction is closed or persistence
602 /// rejects the locator.
603 fn add_locator(&mut self, locator: &Locator) -> Result<()>;
604
605 /// Confirms a locator from a read-bound decision, preserving identical facts.
606 ///
607 /// Returns false for an existing resource/URI/naming identity and true for
608 /// a new location. An unchanged confirmation still guards the locator set;
609 /// it does not rewrite root annotations, availability or last-seen facts.
610 /// # Errors
611 /// Rejects absent decision bases, invalid/missing resources and storage errors.
612 fn confirm_locator(&mut self, locator: &Locator) -> Result<bool>;
613
614 /// Stages retirement of one superseded resource locator.
615 ///
616 /// Requires a decision base. Early rejection leaves the transaction open.
617 ///
618 /// # Errors
619 ///
620 /// Returns a domain error when the transaction is closed, the locator does
621 /// not exist, or persistence fails.
622 fn retire_locator(&mut self, locator_id: crate::LocatorId) -> Result<()>;
623
624 /// Stages a configured resolver search root.
625 ///
626 /// # Errors
627 ///
628 /// Returns a domain error when the transaction is closed or persistence
629 /// rejects the root.
630 fn add_media_root(&mut self, root: MediaRoot) -> Result<()>;
631
632 /// Enables or disables a configured resolver search root.
633 ///
634 /// Requires an edit with a decision base. Setting the existing state is an
635 /// idempotent no-op; early rejection leaves the transaction open.
636 ///
637 /// # Errors
638 ///
639 /// Returns a domain error when the transaction is closed, the root does not
640 /// exist, or persistence fails.
641 fn set_media_root_enabled(&mut self, root_id: crate::MediaRootId, enabled: bool) -> Result<()>;
642
643 /// Stages removal of a configured resolver search root.
644 /// Requires an edit with a decision base; early rejection leaves it open.
645 ///
646 /// # Errors
647 ///
648 /// Returns a domain error when the transaction is closed, the root does not
649 /// exist, or persistence fails.
650 fn remove_media_root(&mut self, root_id: crate::MediaRootId) -> Result<()>;
651
652 /// Stages an external identifier attachment.
653 ///
654 /// # Errors
655 ///
656 /// Returns a domain error when the transaction is closed, the target does
657 /// not exist, the attachment already exists, or persistence fails.
658 fn add_external_identifier(
659 &mut self,
660 target: ObjectRef,
661 identifier: &ExternalIdentifier,
662 ) -> Result<()>;
663
664 /// Stages removal of one exact external identifier attachment.
665 ///
666 /// Requires a decision base. Early rejection leaves the transaction open.
667 ///
668 /// # Errors
669 ///
670 /// Returns a domain error when the transaction is closed, the attachment
671 /// does not exist, the target kind is unsupported, or persistence fails.
672 fn remove_external_identifier(
673 &mut self,
674 target: ObjectRef,
675 identifier: &ExternalIdentifier,
676 ) -> Result<()>;
677
678 /// Appends one value to an object's metadata property.
679 ///
680 /// # Errors
681 ///
682 /// Returns a domain error when the transaction is closed, the target does
683 /// not exist or is unsupported, encoding fails, or persistence fails.
684 fn add_metadata_value(
685 &mut self,
686 target: ObjectRef,
687 property: &MetadataProperty,
688 value: &MetadataValue,
689 ) -> Result<()>;
690
691 /// Atomically replaces all values of one metadata property.
692 ///
693 /// An empty value slice removes the property.
694 /// Requires a decision base; unbased transactions may append values.
695 ///
696 /// # Errors
697 ///
698 /// Returns a domain error when a decision base is absent, the transaction
699 /// is closed, the target is absent/unsupported, or encoding/persistence fails.
700 fn replace_metadata_values(
701 &mut self,
702 target: ObjectRef,
703 property: &MetadataProperty,
704 values: &[MetadataValue],
705 ) -> Result<()>;
706
707 /// Removes all values of one metadata property.
708 /// Requires a decision base.
709 ///
710 /// # Errors
711 ///
712 /// Returns a domain error when a decision base is absent, the transaction
713 /// is closed, the property is absent, or the target/persistence fails.
714 fn remove_metadata_property(
715 &mut self,
716 target: ObjectRef,
717 property: &MetadataProperty,
718 ) -> Result<()>;
719
720 /// Stages a complete production activity with its input and output edges.
721 ///
722 /// # Errors
723 ///
724 /// Returns a domain error when the transaction is closed, a referenced
725 /// representation is absent, the activity already exists, its edges would
726 /// create a provenance cycle, or persistence fails.
727 fn create_activity(&mut self, activity: &Activity) -> Result<()>;
728
729 /// Replaces one representation's complete ordered dependency observation.
730 ///
731 /// Returns `true` when state changed and `false` for an identical current
732 /// observation. An empty slice explicitly records a known empty set.
733 /// Requires a decision base, including initial and unchanged observations;
734 /// early rejection leaves the transaction open.
735 ///
736 /// # Errors
737 ///
738 /// Returns a domain error when the transaction is closed, a referenced
739 /// object is absent or inconsistent, or persistence fails.
740 fn record_dependency_set(
741 &mut self,
742 representation_id: RepresentationId,
743 dependencies: &[Dependency],
744 ) -> Result<bool>;
745
746 /// Records a resource fingerprint as the current observation in its domain.
747 ///
748 /// Requires a decision base, including first and unchanged observations.
749 /// Returns `true` when state changed and `false` for an identical no-op.
750 ///
751 /// # Errors
752 ///
753 /// Returns a domain error when the transaction is closed, the resource is
754 /// absent, or persistence fails.
755 fn record_resource_fingerprint(
756 &mut self,
757 resource_id: ResourceId,
758 fingerprint: &ResourceFingerprint,
759 ) -> Result<bool>;
760
761 /// Records a resource's current size and modification time as part of a
762 /// content observation. Changed facts emit an event and guard the resource's
763 /// file-facts conflict key. Requires a decision base; facts have no history.
764 ///
765 /// Returns `true` when state changed and `false` for identical facts.
766 ///
767 /// # Errors
768 ///
769 /// Returns a domain error when the transaction is closed, the resource is
770 /// absent, or persistence fails.
771 fn record_resource_file_facts(
772 &mut self,
773 resource_id: ResourceId,
774 facts: FileFacts,
775 ) -> Result<bool>;
776
777 /// Records a representation fingerprint as the current observation.
778 ///
779 /// Requires a decision base, including first and unchanged observations.
780 /// Returns `true` when state changed and `false` for an identical no-op.
781 /// A changed observation clears that representation's recomputation marker.
782 ///
783 /// # Errors
784 ///
785 /// Returns a domain error when the transaction is closed, the
786 /// representation is absent, or persistence fails.
787 fn record_representation_fingerprint(
788 &mut self,
789 representation_id: RepresentationId,
790 fingerprint: &RepresentationFingerprint,
791 ) -> Result<bool>;
792
793 /// Stages one requested job with its canonical inputs.
794 ///
795 /// # Errors
796 ///
797 /// Returns a domain error when the transaction is closed, the supplied job
798 /// is not requested, a referenced object is absent, the job already exists,
799 /// or persistence fails.
800 fn request_job(&mut self, job: &Job) -> Result<()>;
801
802 /// Claims work for a checked duration using current store authority time.
803 ///
804 /// # Errors
805 /// Rejects invalid durations, unavailable jobs, clock rollback or storage errors.
806 fn claim_job_lease(
807 &mut self,
808 job: JobId,
809 tool: &ToolIdentity,
810 agent: Option<&AgentIdentity>,
811 duration: Duration,
812 ) -> Result<Self::Lease>;
813
814 /// Renews current ownership; the edit must commit before its previous expiry.
815 ///
816 /// # Errors
817 /// Rejects wrong scope, expired/superseded ownership, invalid duration or storage errors.
818 fn renew_job_lease(&mut self, lease: &Self::Lease, duration: Duration) -> Result<()>;
819
820 /// Releases current unexpired ownership, closing the handle on commit.
821 ///
822 /// # Errors
823 /// Rejects wrong scope, expired/superseded ownership or storage errors.
824 fn release_job_lease(&mut self, lease: &Self::Lease) -> Result<()>;
825
826 /// Fails current unexpired ownership, closing the handle on commit.
827 ///
828 /// # Errors
829 /// Rejects wrong scope, expired/superseded ownership or storage errors.
830 fn fail_job_lease(&mut self, lease: &Self::Lease, failure: &JobFailure) -> Result<()>;
831
832 /// Atomically publishes requested output/provenance and closes ownership.
833 ///
834 /// # Errors
835 /// Rejects wrong scope, expired/superseded ownership, invalid facts or storage errors.
836 fn complete_job_lease(
837 &mut self,
838 lease: &Self::Lease,
839 output: &RepresentationImport,
840 activity: &Activity,
841 ) -> Result<()>;
842
843 /// Cancels a requested or claimed job administratively.
844 ///
845 /// # Errors
846 ///
847 /// Returns a domain error when the job is absent or terminal, the
848 /// transaction is closed, or persistence fails.
849 fn cancel_job(&mut self, job_id: JobId) -> Result<()>;
850
851 /// Commits atomically and returns only the revision this transaction made.
852 ///
853 /// A commit attempt is terminal, including failure. An absent revision in
854 /// the receipt means that no new revision was created.
855 ///
856 /// # Errors
857 ///
858 /// Returns structured semantic conflicts, closed-state or storage errors.
859 fn commit(&mut self) -> Result<CommitReceipt>;
860
861 /// Explicitly discards every staged mutation.
862 ///
863 /// # Errors
864 ///
865 /// Returns a domain error when the transaction is closed or rollback fails.
866 fn rollback(&mut self) -> Result<()>;
867}
868
869/// A production persistence backend with explicit domain transactions.
870pub trait ProductionStore: ProductionRead {
871 /// Backend-owned worker capability shared by its domain edits.
872 type Lease: crate::JobLease;
873
874 /// Imports explicit scoped credentials against current store authority.
875 ///
876 /// # Errors
877 /// Rejects invalid scope/encoding, expired/superseded claims or storage errors.
878 fn import_job_lease(&mut self, token: &str) -> Result<Self::Lease>;
879 /// Independently owned coherent read view.
880 type ReadSession: ProductionReadSession;
881
882 /// Opens a coherent view and captures its decision base.
883 ///
884 /// # Errors
885 ///
886 /// Returns storage errors or a changed-production conflict.
887 fn read_session(&self) -> Result<Self::ReadSession>;
888
889 /// Begins a short write guarded by a production-scoped decision base.
890 ///
891 /// # Errors
892 ///
893 /// Rejects wrong scope and invalid revisions, or returns storage errors.
894 fn begin_edit(&mut self, base: DecisionBase) -> Result<Self::Transaction<'_>>;
895 /// Backend-specific transaction implementation borrowing this store.
896 type Transaction<'production>: ProductionStoreTransaction<Lease = Self::Lease>
897 where
898 Self: 'production;
899
900 /// Begins a transaction for domain mutations.
901 ///
902 /// # Errors
903 ///
904 /// Returns a storage-domain error when a transaction cannot be started.
905 fn begin_transaction(&mut self) -> Result<Self::Transaction<'_>>;
906
907 /// Begins a transaction whose decisions were made from `base_revision`.
908 ///
909 /// Independent additive work may still commit. A commit that touches a
910 /// non-mergeable semantic fact changed after the base fails atomically
911 /// with structured conflict detail.
912 ///
913 /// # Errors
914 ///
915 /// Returns [`crate::ErrorKind::NotFound`] when the base revision does not exist,
916 /// or a storage-domain error when a transaction cannot be started.
917 fn begin_transaction_at(
918 &mut self,
919 base_revision: crate::RevisionId,
920 ) -> Result<Self::Transaction<'_>>;
921}