Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update rexie, dashmap, and rstest deps #24

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 58 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ categories = ["asynchronous", "data-structures"]

[dependencies]
cid = "0.11.0"
dashmap = "5.5.3"
dashmap = "6.0.1"
lru = { version = "0.12.2", optional = true }
multihash = "0.19.1"
thiserror = "1.0.40"
Expand All @@ -31,11 +31,12 @@ tokio = { version = "1.29.0", features = ["macros", "rt"], optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = { version = "0.3.68", optional = true }
rexie = { version = "0.5.0", optional = true }
rexie = { version = "0.6.1", optional = true }
idb = { version = "0.6.2", optional = true }
wasm-bindgen = { version = "0.2.91", optional = true }

[dev-dependencies]
rstest = "0.18.2"
rstest = "0.22.0"
tokio = { version = "1.29.0", features = ["macros", "rt"] }
tempfile = "3.10"

Expand Down
40 changes: 22 additions & 18 deletions src/indexed_db_blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,20 @@ impl Blockstore for IndexedDbBlockstore {
.db
.transaction(&[BLOCK_STORE], TransactionMode::ReadOnly)?;
let blocks = tx.store(BLOCK_STORE)?;
let block = blocks.get(&cid).await?;

if block.is_undefined() {
Ok(None)
} else {
let arr = block.dyn_ref::<Uint8Array>().ok_or_else(|| {
Error::StoredDataError(format!(
"expected 'Uint8Array', got '{}'",
block
.js_typeof()
.as_string()
.expect("typeof must be a string")
))
})?;
Ok(Some(arr.to_vec()))
}
let Some(block) = blocks.get(cid.into()).await? else {
return Ok(None);
};

let arr = block.dyn_ref::<Uint8Array>().ok_or_else(|| {
Error::StoredDataError(format!(
"expected 'Uint8Array', got '{}'",
block
.js_typeof()
.as_string()
.expect("typeof must be a string")
))
})?;
Ok(Some(arr.to_vec()))
}

async fn put_keyed<const S: usize>(&self, cid: &CidGeneric<S>, data: &[u8]) -> Result<()> {
Expand All @@ -91,7 +89,7 @@ impl Blockstore for IndexedDbBlockstore {
.transaction(&[BLOCK_STORE], TransactionMode::ReadWrite)?;
let blocks = tx.store(BLOCK_STORE)?;

blocks.delete(&cid).await?;
blocks.delete(cid.into()).await?;

Ok(())
}
Expand All @@ -114,9 +112,15 @@ impl From<rexie::Error> for Error {
}
}

impl From<idb::Error> for Error {
fn from(value: idb::Error) -> Self {
Error::FatalDatabaseError(value.to_string())
}
}

async fn has_key(store: &Store, key: &JsValue) -> Result<bool> {
let key_range = KeyRange::only(key)?;
let count = store.count(Some(&key_range)).await?;
let count = store.count(Some(key_range)).await?;
Ok(count > 0)
}

Expand Down
Loading