//! Repository trait definitions (pure — no impls, no concrete persistence). //! //! Defines the repository contracts that infrastructure adapters implement. //! Following clean architecture, domain code depends only on these traits, //! not on concrete persistence libraries. //! //! # Traits //! //! - [`SessionRepository`] — CRUD for session metadata //! - [`SessionLockRepository`] — acquire/release/liveness for session locks //! - [`OAuthRepository`] — persist/load OAuth tokens use std::path::Path; use crate::auth::error::RepositoryError; use crate::auth::oauth::OAuthToken; use crate::auth::session::Session; use crate::auth::session_id::SessionId; /// Repository for loading, saving, listing, and deleting sessions. pub trait SessionRepository { /// List all loadable sessions under `/sessions/`. fn list_sessions(&self, base_dir: &Path) -> Result, RepositoryError>; /// Load a single session by id. fn load_session(&self, base_dir: &Path, id: &SessionId) -> Result; /// Save a session's metadata to disk. fn save_session(&self, base_dir: &Path, session: &Session) -> Result<(), RepositoryError>; /// Delete a session directory and all its contents. fn delete_session(&self, base_dir: &Path, id: &SessionId) -> Result<(), RepositoryError>; } /// Repository for per-session PID-file advisory locks. pub trait SessionLockRepository { /// Try to acquire the lock for a session directory. /// Returns `true` if the lock was acquired, `false` if another live /// process holds it. fn try_lock(&self, session_dir: &Path) -> Result; /// Release the lock by removing the lock file. fn unlock(&self, session_dir: &Path) -> Result<(), RepositoryError>; /// Check whether a process with the given PID is alive. fn is_alive(&self, pid: u32) -> bool; } /// Repository for persisting and loading OAuth tokens. pub trait OAuthRepository { /// Persist an OAuth token to a JSON file. fn save_token(&self, path: &Path, token: &OAuthToken) -> Result<(), RepositoryError>; /// Load an OAuth token from a JSON file, returning `None` if the file /// does not exist. fn load_token(&self, path: &Path) -> Result, RepositoryError>; }