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