openzeppelin_relayer/repositories/
mod.rs1use crate::models::{PaginationQuery, RepositoryError};
6use async_trait::async_trait;
7use eyre::Result;
8
9mod relayer;
10pub use relayer::*;
11
12pub mod transaction;
13pub use transaction::*;
14
15mod signer;
16pub use signer::*;
17
18mod notification;
19pub use notification::*;
20
21mod transaction_counter;
22pub use transaction_counter::*;
23
24mod network;
25pub use network::*;
26
27mod plugin;
28pub use plugin::*;
29
30#[derive(Debug)]
31pub struct PaginatedResult<T> {
32 pub items: Vec<T>,
33 pub total: u64,
34 pub page: u32,
35 pub per_page: u32,
36}
37#[cfg(test)]
38use mockall::automock;
39
40#[async_trait]
41#[allow(dead_code)]
42#[cfg_attr(test, automock)]
43pub trait Repository<T, ID> {
44 async fn create(&self, entity: T) -> Result<T, RepositoryError>;
45 async fn get_by_id(&self, id: ID) -> Result<T, RepositoryError>;
46 async fn list_all(&self) -> Result<Vec<T>, RepositoryError>;
47 async fn list_paginated(
48 &self,
49 query: PaginationQuery,
50 ) -> Result<PaginatedResult<T>, RepositoryError>;
51 async fn update(&self, id: ID, entity: T) -> Result<T, RepositoryError>;
52 async fn delete_by_id(&self, id: ID) -> Result<(), RepositoryError>;
53 async fn count(&self) -> Result<usize, RepositoryError>;
54}