From 79a0aaf5cd81cf2949777f876a168887c0ab01e2 Mon Sep 17 00:00:00 2001 From: sugyan Date: Wed, 14 Aug 2024 00:41:15 +0900 Subject: [PATCH 1/2] Use primitives-as-trait branch --- Cargo.lock | 3 +-- Cargo.toml | 4 ++++ atrium-api/src/types.rs | 41 +++++++++++++++++++++++------------------ 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1cfb7058..450533c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1114,8 +1114,7 @@ dependencies = [ [[package]] name = "ipld-core" version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ede82a79e134f179f4b29b5fdb1eb92bd1b38c4dfea394c539051150a21b9b" +source = "git+https://github.com/ipld/rust-ipld-core?branch=primitives-as-trait#4ef5d7344881d0c6c0824f40922bd3f5163320b6" dependencies = [ "cid", "serde", diff --git a/Cargo.toml b/Cargo.toml index 83e5cdae..6f57c3a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = "primitives-as-trait" } diff --git a/atrium-api/src/types.rs b/atrium-api/src/types.rs index 432266d6..42a1d89f 100644 --- a/atrium-api/src/types.rs +++ b/atrium-api/src/types.rs @@ -2,7 +2,8 @@ //! use crate::error::Error; -use ipld_core::ipld::Ipld; +use ipld_core::cid::Cid; +use ipld_core::ipld::{IpldGeneric, Primitives}; use ipld_core::serde::to_ipld; use std::collections::BTreeMap; use std::fmt; @@ -17,6 +18,20 @@ pub use integer::*; pub mod string; use string::RecordKey; +#[derive(Clone)] +pub struct PrimitivesI64; + +impl Primitives for PrimitivesI64 { + type Bool = bool; + type Integer = i64; + type Float = f64; + type String = String; + type Bytes = Vec; + type Link = Cid; +} + +type Ipld = IpldGeneric; + /// Trait for a collection of records that can be stored in a repository. /// /// The records all have the same Lexicon schema. @@ -214,23 +229,13 @@ where type Error = Error; fn try_from_unknown(value: Unknown) -> Result { - // 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)?, + }) } } From 15a9aa73e7c80fbeb5f5e6cc8176b3fd40a60443 Mon Sep 17 00:00:00 2001 From: sugyan Date: Tue, 3 Sep 2024 12:08:39 +0900 Subject: [PATCH 2/2] Use integer-max-i64-feature branch --- Cargo.lock | 2 +- Cargo.toml | 4 ++-- atrium-api/src/types.rs | 14 +------------- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 450533c3..0f3dc8eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1114,7 +1114,7 @@ dependencies = [ [[package]] name = "ipld-core" version = "0.4.1" -source = "git+https://github.com/ipld/rust-ipld-core?branch=primitives-as-trait#4ef5d7344881d0c6c0824f40922bd3f5163320b6" +source = "git+https://github.com/ipld/rust-ipld-core?branch=integer-max-i64-feature#90adbf73b6472de56d13a7388c51da00844e8c1f" dependencies = [ "cid", "serde", diff --git a/Cargo.toml b/Cargo.toml index 6f57c3a4..bb5f0be2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 @@ -79,4 +79,4 @@ bumpalo = "~3.14.0" [patch.crates-io] -ipld-core = { git = "https://github.com/ipld/rust-ipld-core", branch = "primitives-as-trait" } +ipld-core = { git = "https://github.com/ipld/rust-ipld-core", branch = "integer-max-i64-feature" } diff --git a/atrium-api/src/types.rs b/atrium-api/src/types.rs index 42a1d89f..affcdccc 100644 --- a/atrium-api/src/types.rs +++ b/atrium-api/src/types.rs @@ -2,8 +2,7 @@ //! use crate::error::Error; -use ipld_core::cid::Cid; -use ipld_core::ipld::{IpldGeneric, Primitives}; +use ipld_core::ipld::Ipld; use ipld_core::serde::to_ipld; use std::collections::BTreeMap; use std::fmt; @@ -21,17 +20,6 @@ use string::RecordKey; #[derive(Clone)] pub struct PrimitivesI64; -impl Primitives for PrimitivesI64 { - type Bool = bool; - type Integer = i64; - type Float = f64; - type String = String; - type Bytes = Vec; - type Link = Cid; -} - -type Ipld = IpldGeneric; - /// Trait for a collection of records that can be stored in a repository. /// /// The records all have the same Lexicon schema.