Skip to content

Commit 2be9325

Browse files
committed
chore: rm PaginationInfo
1 parent 2d22d48 commit 2be9325

File tree

1 file changed

+19
-49
lines changed

1 file changed

+19
-49
lines changed

crates/tx-cache/src/types.rs

Lines changed: 19 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! The endpoints for the transaction cache.
22
use alloy::{consensus::TxEnvelope, primitives::B256};
33
use serde::{
4-
de::{MapAccess, SeqAccess, Visitor},
4+
de::{DeserializeOwned, MapAccess, SeqAccess, Visitor},
55
Deserialize, Deserializer, Serialize,
66
};
77
use signet_bundle::SignetEthBundle;
@@ -11,20 +11,20 @@ use uuid::Uuid;
1111
/// A trait for types that can be used as a cache object.
1212
pub trait CacheObject {
1313
/// The cursor key type for the cache object.
14-
type Key: Serialize + for<'a> Deserialize<'a>;
14+
type Key: Serialize + DeserializeOwned;
1515
}
1616

1717
/// A response from the transaction cache, containing an item.
1818
#[derive(Debug, Clone, Serialize, Deserialize)]
1919
#[serde(untagged)]
2020
pub enum CacheResponse<T: CacheObject> {
21-
/// A paginated response, containing the inner item and a pagination info.
21+
/// A paginated response, containing the inner item and a next cursor.
2222
Paginated {
2323
/// The actual item.
2424
#[serde(flatten)]
2525
inner: T,
26-
/// The pagination info.
27-
pagination: PaginationInfo<T::Key>,
26+
/// The next cursor for pagination, if any.
27+
next_cursor: Option<T::Key>,
2828
},
2929
/// An unpaginated response, containing the actual item.
3030
Unpaginated {
@@ -40,8 +40,8 @@ impl<T: CacheObject> CacheObject for CacheResponse<T> {
4040

4141
impl<T: CacheObject> CacheResponse<T> {
4242
/// Create a new paginated response from a list of items and a pagination info.
43-
pub const fn paginated(inner: T, pagination: PaginationInfo<T::Key>) -> Self {
44-
Self::Paginated { inner, pagination }
43+
pub const fn paginated(inner: T, pagination: T::Key) -> Self {
44+
Self::Paginated { inner, next_cursor: Some(pagination) }
4545
}
4646

4747
/// Create a new unpaginated response from a list of items.
@@ -65,14 +65,19 @@ impl<T: CacheObject> CacheResponse<T> {
6565
}
6666
}
6767

68-
/// Return the pagination info, if any.
69-
pub const fn pagination_info(&self) -> Option<&PaginationInfo<T::Key>> {
68+
/// Return the next cursor for pagination, if any.
69+
pub const fn next_cursor(&self) -> Option<&T::Key> {
7070
match self {
71-
Self::Paginated { pagination, .. } => Some(pagination),
71+
Self::Paginated { next_cursor, .. } => next_cursor.as_ref(),
7272
Self::Unpaginated { .. } => None,
7373
}
7474
}
7575

76+
/// Check if the response has more items to fetch.
77+
pub const fn has_more(&self) -> bool {
78+
self.next_cursor().is_some()
79+
}
80+
7681
/// Check if the response is paginated.
7782
pub const fn is_paginated(&self) -> bool {
7883
matches!(self, Self::Paginated { .. })
@@ -92,15 +97,15 @@ impl<T: CacheObject> CacheResponse<T> {
9297
}
9398

9499
/// Consume the response and return the parts.
95-
pub fn into_parts(self) -> (T, Option<PaginationInfo<T::Key>>) {
100+
pub fn into_parts(self) -> (T, Option<T::Key>) {
96101
match self {
97-
Self::Paginated { inner, pagination } => (inner, Some(pagination)),
102+
Self::Paginated { inner, next_cursor } => (inner, next_cursor),
98103
Self::Unpaginated { inner } => (inner, None),
99104
}
100105
}
101106

102-
/// Consume the response and return the pagination info, if any.
103-
pub fn into_pagination_info(self) -> Option<PaginationInfo<T::Key>> {
107+
/// Consume the response and return the next cursor for pagination, if any.
108+
pub fn into_next_cursor(self) -> Option<T::Key> {
104109
self.into_parts().1
105110
}
106111
}
@@ -428,41 +433,6 @@ impl TxCacheSendOrderResponse {
428433
}
429434
}
430435

431-
/// Represents the pagination information from a transaction cache response.
432-
/// This applies to all GET endpoints that return a list of items.
433-
#[derive(Debug, Clone, Serialize, Deserialize)]
434-
pub struct PaginationInfo<C> {
435-
/// The next cursor.
436-
next_cursor: Option<C>,
437-
}
438-
439-
impl<C> PaginationInfo<C> {
440-
/// Create a new [`PaginationInfo`].
441-
pub const fn new(next_cursor: Option<C>) -> Self {
442-
Self { next_cursor }
443-
}
444-
445-
/// Create an empty [`PaginationInfo`].
446-
pub const fn empty() -> Self {
447-
Self { next_cursor: None }
448-
}
449-
450-
/// Get the next cursor.
451-
pub const fn next_cursor(&self) -> Option<&C> {
452-
self.next_cursor.as_ref()
453-
}
454-
455-
/// Consume the [`PaginationInfo`] and return the next cursor.
456-
pub fn into_next_cursor(self) -> Option<C> {
457-
self.next_cursor
458-
}
459-
460-
/// Check if there is a next page in the response.
461-
pub const fn has_next_page(&self) -> bool {
462-
self.next_cursor.is_some()
463-
}
464-
}
465-
466436
/// The query object keys for the transaction GET endpoint.
467437
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
468438
#[serde(rename_all = "camelCase")]

0 commit comments

Comments
 (0)