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