refactor(indexeddb): rename IndexeddbMediaStoreSerializer{Error} to IndexedTypeSerializer{Error}

Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
This commit is contained in:
Michael Goldenberg
2025-09-13 20:16:55 -04:00
committed by Ivan Enderlin
parent b9410dff61
commit 0e4e4eae2b
4 changed files with 15 additions and 27 deletions

View File

@@ -20,7 +20,7 @@ use matrix_sdk_store_encryption::StoreCipher;
use crate::{
media_store::{
error::IndexeddbMediaStoreError, migrations::open_and_upgrade_db,
serializer::IndexeddbMediaStoreSerializer, IndexeddbMediaStore,
serializer::IndexedTypeSerializer, IndexeddbMediaStore,
},
serializer::SafeEncodeSerializer,
};
@@ -66,9 +66,7 @@ impl IndexeddbMediaStoreBuilder {
pub async fn build(self) -> Result<IndexeddbMediaStore, IndexeddbMediaStoreError> {
Ok(IndexeddbMediaStore {
inner: Rc::new(open_and_upgrade_db(&self.database_name).await?),
serializer: IndexeddbMediaStoreSerializer::new(SafeEncodeSerializer::new(
self.store_cipher,
)),
serializer: IndexedTypeSerializer::new(SafeEncodeSerializer::new(self.store_cipher)),
media_service: MediaService::new(),
memory_store: MemoryMediaStore::new(),
})

View File

@@ -36,7 +36,7 @@ use matrix_sdk_base::{
timer,
};
use ruma::{time::SystemTime, MilliSecondsSinceUnixEpoch, MxcUri};
use serializer::IndexeddbMediaStoreSerializer;
use serializer::IndexedTypeSerializer;
use tracing::instrument;
use web_sys::IdbTransactionMode;
@@ -54,7 +54,7 @@ pub struct IndexeddbMediaStore {
// A handle to the IndexedDB database
inner: Rc<IdbDatabase>,
// A serializer with functionality tailored to `IndexeddbMediaStore`
serializer: IndexeddbMediaStoreSerializer,
serializer: IndexedTypeSerializer,
// A service for conveniently delegating media-related queries to an `MediaStoreInner`
// implementation
media_service: MediaService,

View File

@@ -31,14 +31,14 @@ pub mod traits;
pub mod types;
#[derive(Debug, Error)]
pub enum IndexeddbMediaStoreSerializerError<IndexingError> {
pub enum IndexedTypeSerializerError<IndexingError> {
#[error("indexing: {0}")]
Indexing(IndexingError),
#[error("serialization: {0}")]
Serialization(#[from] serde_json::Error),
}
impl<T> From<serde_wasm_bindgen::Error> for IndexeddbMediaStoreSerializerError<T> {
impl<T> From<serde_wasm_bindgen::Error> for IndexedTypeSerializerError<T> {
fn from(e: serde_wasm_bindgen::Error) -> Self {
Self::Serialization(serde::de::Error::custom(e.to_string()))
}
@@ -52,11 +52,11 @@ impl<T> From<serde_wasm_bindgen::Error> for IndexeddbMediaStoreSerializerError<T
///
/// [1]: matrix_sdk_base::media::store::MediaStore
#[derive(Debug, Clone)]
pub struct IndexeddbMediaStoreSerializer {
pub struct IndexedTypeSerializer {
inner: SafeEncodeSerializer,
}
impl IndexeddbMediaStoreSerializer {
impl IndexedTypeSerializer {
pub fn new(inner: SafeEncodeSerializer) -> Self {
Self { inner }
}
@@ -140,29 +140,22 @@ impl IndexeddbMediaStoreSerializer {
}
/// Serializes an [`Indexed`] type into a [`JsValue`]
pub fn serialize<T>(
&self,
t: &T,
) -> Result<JsValue, IndexeddbMediaStoreSerializerError<T::Error>>
pub fn serialize<T>(&self, t: &T) -> Result<JsValue, IndexedTypeSerializerError<T::Error>>
where
T: Indexed,
T::IndexedType: Serialize,
{
let indexed =
t.to_indexed(&self.inner).map_err(IndexeddbMediaStoreSerializerError::Indexing)?;
let indexed = t.to_indexed(&self.inner).map_err(IndexedTypeSerializerError::Indexing)?;
serde_wasm_bindgen::to_value(&indexed).map_err(Into::into)
}
/// Deserializes an [`Indexed`] type from a [`JsValue`]
pub fn deserialize<T>(
&self,
value: JsValue,
) -> Result<T, IndexeddbMediaStoreSerializerError<T::Error>>
pub fn deserialize<T>(&self, value: JsValue) -> Result<T, IndexedTypeSerializerError<T::Error>>
where
T: Indexed,
T::IndexedType: DeserializeOwned,
{
let indexed: T::IndexedType = value.into_serde()?;
T::from_indexed(indexed, &self.inner).map_err(IndexeddbMediaStoreSerializerError::Indexing)
T::from_indexed(indexed, &self.inner).map_err(IndexedTypeSerializerError::Indexing)
}
}

View File

@@ -26,7 +26,7 @@ use crate::media_store::{
serializer::{
traits::{Indexed, IndexedKey},
types::{IndexedCoreIdKey, IndexedKeyRange, IndexedLeaseIdKey},
IndexeddbMediaStoreSerializer,
IndexedTypeSerializer,
},
types::Lease,
};
@@ -72,14 +72,11 @@ impl From<IndexeddbMediaStoreTransactionError> for MediaStoreError {
/// [`MediaStore`](matrix_sdk_base::media::store::MediaStore).
pub struct IndexeddbMediaStoreTransaction<'a> {
transaction: IdbTransaction<'a>,
serializer: &'a IndexeddbMediaStoreSerializer,
serializer: &'a IndexedTypeSerializer,
}
impl<'a> IndexeddbMediaStoreTransaction<'a> {
pub fn new(
transaction: IdbTransaction<'a>,
serializer: &'a IndexeddbMediaStoreSerializer,
) -> Self {
pub fn new(transaction: IdbTransaction<'a>, serializer: &'a IndexedTypeSerializer) -> Self {
Self { transaction, serializer }
}