openzeppelin_relayer/repositories/
mod.rs1use 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 redis_base;
34
35#[derive(Debug, Serialize, Deserialize, ToSchema)]
36pub struct PaginatedResult<T> {
37 pub items: Vec<T>,
38 pub total: u64,
39 pub page: u32,
40 pub per_page: u32,
41}
42
43pub struct BatchRetrievalResult<T> {
44 pub results: Vec<T>,
45 pub failed_ids: Vec<String>,
46}
47
48#[cfg(test)]
49use mockall::automock;
50use utoipa::ToSchema;
51
52#[async_trait]
53#[allow(dead_code)]
54#[cfg_attr(test, automock)]
55pub trait Repository<T, ID> {
56 async fn create(&self, entity: T) -> Result<T, RepositoryError>;
57 async fn get_by_id(&self, id: ID) -> Result<T, RepositoryError>;
58 async fn list_all(&self) -> Result<Vec<T>, RepositoryError>;
59 async fn list_paginated(
60 &self,
61 query: PaginationQuery,
62 ) -> Result<PaginatedResult<T>, RepositoryError>;
63 async fn update(&self, id: ID, entity: T) -> Result<T, RepositoryError>;
64 async fn delete_by_id(&self, id: ID) -> Result<(), RepositoryError>;
65 async fn count(&self) -> Result<usize, RepositoryError>;
66
67 async fn has_entries(&self) -> Result<bool, RepositoryError>;
69
70 async fn drop_all_entries(&self) -> Result<(), RepositoryError>;
74}
75
76#[derive(Error, Debug)]
77pub enum ConversionError {
78 #[error("Invalid type: {0}")]
79 InvalidType(String),
80 #[error("Invalid config: {0}")]
81 InvalidConfig(String),
82}