steid

@jamesgill /

1//! Repository ports.
2//!
3//! Traits only — the domain declares what persistence it needs, and
4//! `infrastructure` supplies it. Every port has two implementations: an in-memory one
5//! that makes use cases testable without a database, and a SQLite one for real use.
6
7pub mod issue_repo;
8pub mod membership_repo;
9pub mod org_repo;
10pub mod push_event_repo;
11pub mod repo_repo;
12pub mod session_repo;
13pub mod token_repo;
14pub mod user_repo;
15pub mod webhook_delivery_repo;
16pub mod webhook_repo;
17
18pub use issue_repo::{IssueCounts, IssueRepository};
19pub use membership_repo::MembershipRepository;
20pub use org_repo::OrgRepository;
21pub use push_event_repo::PushEventRepository;
22pub use repo_repo::RepoRepository;
23pub use session_repo::SessionRepository;
24pub use token_repo::TokenRepository;
25pub use user_repo::UserRepository;
26pub use webhook_delivery_repo::WebhookDeliveryRepository;
27pub use webhook_repo::WebhookRepository;
28
29/// What a repository can fail with.
30///
31/// Storage failures are infrastructural and carry no domain meaning, so they collapse
32/// into one opaque variant rather than leaking driver types upward.
33#[derive(Debug)]
34pub enum RepositoryError {
35 Backend(Box<dyn std::error::Error + Send + Sync>),
36}
37
38impl RepositoryError {
39 pub fn backend(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self {
40 Self::Backend(error.into())
41 }
42}
43
44impl std::fmt::Display for RepositoryError {
45 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 match self {
47 Self::Backend(error) => write!(f, "storage failure: {error}"),
48 }
49 }
50}
51
52impl std::error::Error for RepositoryError {
53 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
54 match self {
55 Self::Backend(error) => Some(&**error),
56 }
57 }
58}
59
60pub type RepositoryResult<T> = Result<T, RepositoryError>;