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 label_repo;
9pub mod membership_repo;
10pub mod org_repo;
11pub mod pull_request_repo;
12pub mod push_event_repo;
13pub mod repo_repo;
14pub mod session_repo;
15pub mod token_repo;
16pub mod user_repo;
17pub mod webhook_delivery_repo;
18pub mod webhook_repo;
19
20pub use issue_repo::{IssueCounts, IssueRepository};
21pub use label_repo::LabelRepository;
22pub use membership_repo::MembershipRepository;
23pub use org_repo::OrgRepository;
24pub use pull_request_repo::{PullRequestCounts, PullRequestRepository};
25pub use push_event_repo::PushEventRepository;
26pub use repo_repo::RepoRepository;
27pub use session_repo::SessionRepository;
28pub use token_repo::TokenRepository;
29pub use user_repo::UserRepository;
30pub use webhook_delivery_repo::WebhookDeliveryRepository;
31pub use webhook_repo::WebhookRepository;
32
33/// What a repository can fail with.
34///
35/// Storage failures are infrastructural and carry no domain meaning, so they collapse
36/// into one opaque variant rather than leaking driver types upward.
37#[derive(Debug)]
38pub enum RepositoryError {
39 Backend(Box<dyn std::error::Error + Send + Sync>),
40}
41
42impl RepositoryError {
43 pub fn backend(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self {
44 Self::Backend(error.into())
45 }
46}
47
48impl std::fmt::Display for RepositoryError {
49 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50 match self {
51 Self::Backend(error) => write!(f, "storage failure: {error}"),
52 }
53 }
54}
55
56impl std::error::Error for RepositoryError {
57 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
58 match self {
59 Self::Backend(error) => Some(&**error),
60 }
61 }
62}
63
64pub type RepositoryResult<T> = Result<T, RepositoryError>;