openzeppelin_relayer/repositories/
mod.rs

1//! # Repository Module
2//!
3//! Implements data persistence layer for the relayer service using Repository pattern.
4
5use crate::models::{PaginationQuery, RepositoryError};
6use async_trait::async_trait;
7use eyre::Result;
8use serde::{Deserialize, Serialize};
9use thiserror::Error;
10
11mod relayer;
12pub use relayer::*;
13
14pub mod transaction;
15pub use transaction::*;
16
17mod signer;
18pub use signer::*;
19
20pub mod notification;
21pub use notification::*;
22
23mod transaction_counter;
24pub use transaction_counter::*;
25
26pub mod network;
27pub use network::*;
28
29mod plugin;
30pub use plugin::*;
31
32pub mod api_key;
33pub use api_key::*;
34
35// Redis base utilities for shared functionality
36pub mod redis_base;
37
38#[derive(Debug, Serialize, Deserialize, ToSchema)]
39pub struct PaginatedResult<T> {
40    pub items: Vec<T>,
41    pub total: u64,
42    pub page: u32,
43    pub per_page: u32,
44}
45
46pub struct BatchRetrievalResult<T> {
47    pub results: Vec<T>,
48    pub failed_ids: Vec<String>,
49}
50
51#[cfg(test)]
52use mockall::automock;
53use utoipa::ToSchema;
54
55#[async_trait]
56#[allow(dead_code)]
57#[cfg_attr(test, automock)]
58pub trait Repository<T, ID> {
59    async fn create(&self, entity: T) -> Result<T, RepositoryError>;
60    async fn get_by_id(&self, id: ID) -> Result<T, RepositoryError>;
61    async fn list_all(&self) -> Result<Vec<T>, RepositoryError>;
62    async fn list_paginated(
63        &self,
64        query: PaginationQuery,
65    ) -> Result<PaginatedResult<T>, RepositoryError>;
66    async fn update(&self, id: ID, entity: T) -> Result<T, RepositoryError>;
67    async fn delete_by_id(&self, id: ID) -> Result<(), RepositoryError>;
68    async fn count(&self) -> Result<usize, RepositoryError>;
69
70    /// Check if the repository contains any entries.
71    async fn has_entries(&self) -> Result<bool, RepositoryError>;
72
73    /// Drop all entries from storage.
74    /// This completely clears all data, indexes, and metadata.
75    /// Use with caution as this permanently deletes all data.
76    async fn drop_all_entries(&self) -> Result<(), RepositoryError>;
77}
78
79#[derive(Error, Debug)]
80pub enum ConversionError {
81    #[error("Invalid type: {0}")]
82    InvalidType(String),
83    #[error("Invalid config: {0}")]
84    InvalidConfig(String),
85}