chore(indexeddb): Reduce target_arch feature gates

This allows smoother development as a regular 'cargo check' will
validate most of the code. It also makes rust-analyzer work for the
crate without any configuration.
This commit is contained in:
Jonas Platte
2022-08-03 13:17:59 +02:00
committed by Jonas Platte
parent 0b7d0aa780
commit 3a19d8e5bf
3 changed files with 39 additions and 39 deletions

View File

@@ -928,6 +928,7 @@ impl IndexeddbStore {
}
}
#[cfg(target_arch = "wasm32")]
#[async_trait(?Send)]
impl CryptoStore for IndexeddbStore {
async fn load_account(&self) -> Result<Option<ReadOnlyAccount>, CryptoStoreError> {
@@ -1072,7 +1073,7 @@ impl CryptoStore for IndexeddbStore {
}
}
#[cfg(test)]
#[cfg(all(test, target_arch = "wasm32"))]
mod tests {
use matrix_sdk_crypto::cryptostore_integration_tests;
@@ -1093,7 +1094,7 @@ mod tests {
cryptostore_integration_tests! { integration }
}
#[cfg(test)]
#[cfg(all(test, target_arch = "wasm32"))]
#[rustfmt::skip]
mod encrypted_tests {
use super::IndexeddbStore;
@@ -1107,7 +1108,8 @@ mod encrypted_tests {
.await
.expect("Can't create a passphrase protected store")
}
// FIXME: the tests pass, if run one by one, but run all together locally,
// as well as CI fails... see matrix-org/matrix-rust-sdk#661
// cryptostore_integration_tests! { integration }
// FIXME: the tests pass, if run one by one, but run all together locally,
// as well as CI fails... see matrix-org/matrix-rust-sdk#661
// cryptostore_integration_tests! { integration }
}

View File

@@ -1,30 +1,22 @@
#[cfg(target_arch = "wasm32")]
#![cfg_attr(not(target_arch = "wasm32"), allow(unused))]
use matrix_sdk_base::store::{StoreConfig, StoreError};
#[cfg(target_arch = "wasm32")]
use thiserror::Error;
mod safe_encode;
#[cfg(target_arch = "wasm32")]
mod state_store;
#[cfg(target_arch = "wasm32")]
#[cfg(feature = "e2e-encryption")]
mod cryptostore;
mod safe_encode;
mod state_store;
#[cfg(target_arch = "wasm32")]
#[cfg(feature = "e2e-encryption")]
pub use cryptostore::IndexeddbStore as CryptoStore;
#[cfg(target_arch = "wasm32")]
#[cfg(feature = "e2e-encryption")]
use cryptostore::IndexeddbStoreError;
#[cfg(target_arch = "wasm32")]
pub use state_store::{IndexeddbStore as StateStore, IndexeddbStoreBuilder as StateStoreBuilder};
#[cfg(target_arch = "wasm32")]
#[cfg(feature = "e2e-encryption")]
/// Create a [`StateStore`] and a [`CryptoStore`] that use the same name and
/// passphrase.
#[cfg(feature = "e2e-encryption")]
async fn open_stores_with_name(
name: impl Into<String>,
passphrase: Option<&str>,
@@ -44,7 +36,6 @@ async fn open_stores_with_name(
Ok((state_store, crypto_store))
}
#[cfg(target_arch = "wasm32")]
/// Create a [`StoreConfig`] with an opened indexeddb [`StateStore`] that uses
/// the given name and passphrase. If `encryption` is enabled, a [`CryptoStore`]
/// with the same parameters is also opened.
@@ -52,31 +43,36 @@ pub async fn make_store_config(
name: impl Into<String>,
passphrase: Option<&str>,
) -> Result<StoreConfig, OpenStoreError> {
let name = name.into();
#[cfg(feature = "e2e-encryption")]
#[cfg(target_arch = "wasm32")]
{
let (state_store, crypto_store) = open_stores_with_name(name, passphrase).await?;
Ok(StoreConfig::new().state_store(state_store).crypto_store(crypto_store))
}
let name = name.into();
#[cfg(not(feature = "e2e-encryption"))]
{
let mut builder = StateStore::builder();
builder.name(name.clone());
if let Some(passphrase) = passphrase {
builder.passphrase(passphrase.to_owned());
#[cfg(feature = "e2e-encryption")]
{
let (state_store, crypto_store) = open_stores_with_name(name, passphrase).await?;
Ok(StoreConfig::new().state_store(state_store).crypto_store(crypto_store))
}
let state_store = builder.build().await.map_err(StoreError::from)?;
#[cfg(not(feature = "e2e-encryption"))]
{
let mut builder = StateStore::builder();
builder.name(name.clone());
Ok(StoreConfig::new().state_store(state_store))
if let Some(passphrase) = passphrase {
builder.passphrase(passphrase.to_owned());
}
let state_store = builder.build().await.map_err(StoreError::from)?;
Ok(StoreConfig::new().state_store(state_store))
}
}
#[cfg(not(target_arch = "wasm32"))]
panic!("the IndexedDB is only available on the 'wasm32' arch")
}
/// All the errors that can occur when opening an IndexedDB store.
#[cfg(target_arch = "wasm32")]
#[derive(Error, Debug)]
pub enum OpenStoreError {
/// An error occurred with the state store implementation.

View File

@@ -1486,6 +1486,7 @@ impl IndexeddbStore {
}
}
#[cfg(target_arch = "wasm32")]
#[async_trait(?Send)]
impl StateStore for IndexeddbStore {
async fn save_filter(&self, filter_name: &str, filter_id: &str) -> StoreResult<()> {
@@ -1665,7 +1666,7 @@ struct TimelineMetadata {
pub end_position: usize,
}
#[cfg(test)]
#[cfg(all(test, target_arch = "wasm32"))]
mod tests {
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
@@ -1683,7 +1684,7 @@ mod tests {
statestore_integration_tests! { integration }
}
#[cfg(test)]
#[cfg(all(test, target_arch = "wasm32"))]
mod encrypted_tests {
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
@@ -1702,10 +1703,10 @@ mod encrypted_tests {
statestore_integration_tests! { integration }
}
#[cfg(test)]
#[cfg(all(test, target_arch = "wasm32"))]
mod migration_tests {
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
use indexed_db_futures::prelude::*;
use matrix_sdk_test::async_test;
use uuid::Uuid;
@@ -1730,6 +1731,7 @@ mod migration_tests {
db_req.into_future().await?;
Ok(())
}
#[async_test]
pub async fn test_no_upgrade() -> Result<()> {
let name = format!("simple-1.1-no-cipher-{}", Uuid::new_v4().as_hyphenated().to_string());