Skip to content
Draft
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
3 changes: 1 addition & 2 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bsky-sdk = { version = "0.1.6", path = "bsky-sdk" }
async-trait = "0.1.80"

# DAG-CBOR codec
ipld-core = { version = "0.4.1", default-features = false, features = ["std"] }
ipld-core = { version = "0.4.1", default-features = false, features = ["integer-max-i64"] }
serde_ipld_dagcbor = { version = "0.6.0", default-features = false, features = ["std"] }

# Parsing and validation
Expand Down Expand Up @@ -76,3 +76,7 @@ mockito = "1.4"
# WebAssembly
wasm-bindgen-test = "0.3.41"
bumpalo = "~3.14.0"


[patch.crates-io]
ipld-core = { git = "https://github.com/ipld/rust-ipld-core", branch = "integer-max-i64-feature" }
27 changes: 10 additions & 17 deletions atrium-api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ pub use integer::*;
pub mod string;
use string::RecordKey;

#[derive(Clone)]
pub struct PrimitivesI64;

/// Trait for a collection of records that can be stored in a repository.
///
/// The records all have the same Lexicon schema.
Expand Down Expand Up @@ -214,23 +217,13 @@ where
type Error = Error;

fn try_from_unknown(value: Unknown) -> Result<Self, Self::Error> {
// TODO: Fix this
// In the current latest `ipld-core` 0.4.1, deserialize to structs containing untagged/internal tagged does not work correctly when `Ipld::Integer` is included.
// https://github.com/ipld/rust-ipld-core/issues/19
// (It should be possible to convert as follows)
// ```
// Ok(match value {
// Unknown::Object(map) => {
// T::deserialize(Ipld::Map(map.into_iter().map(|(k, v)| (k, v.0)).collect()))?
// }
// Unknown::Null => T::deserialize(Ipld::Null)?,
// Unknown::Other(data) => T::deserialize(data.0)?,
// })
// ```
//
// For the time being, until this problem is resolved, use the workaround of serializing once to a json string and then deserializing it.
let json = serde_json::to_vec(&value).unwrap();
Ok(serde_json::from_slice(&json).unwrap())
Ok(match value {
Unknown::Object(map) => {
T::deserialize(Ipld::Map(map.into_iter().map(|(k, v)| (k, v.0)).collect()))?
}
Unknown::Null => T::deserialize(Ipld::Null)?,
Unknown::Other(data) => T::deserialize(data.0)?,
})
}
}

Expand Down