Skip to content

Commit

Permalink
Introduce dedicated types for DID and handle Lexicon string formats
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Feb 18, 2024
1 parent 948c380 commit 6060a7c
Show file tree
Hide file tree
Showing 81 changed files with 448 additions and 131 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ cid = "0.10.1"
libipld-core = "0.16"
serde_ipld_dagcbor = "0.3"

# Serde
# Parsing and validation
regex = "1"
serde = "1.0.160"
serde_bytes = "0.11.9"
serde_json = "1.0.96"
Expand Down
6 changes: 6 additions & 0 deletions atrium-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `LimitedU16`, `LimitedNonZeroU16`, `BoundedU16`
- `LimitedU32`, `LimitedNonZeroU32`, `BoundedU32`
- `LimitedU64`, `LimitedNonZeroU64`, `BoundedU64`
- `string` module, containing dedicated types for formatted Lexicon strings.

### Changed
- All Lexicon integer fields now have a type that matches their minimum and maximum
accepted values, instead of `i32`.
- All Lexicon string fields with one of the following formats now have the corresponding
dedicated type, instead of `String`:
- `at-identifier` (`atrium_api::types::string::AtIdentifier`)
- `did` (`atrium_api::types::string::Did`)
- `handle` (`atrium_api::types::string::Handle`)

## [0.16.0](https://github.com/sugyan/atrium/compare/atrium-api-v0.15.0...atrium-api-v0.16.0) - 2024-02-09

Expand Down
1 change: 1 addition & 0 deletions atrium-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ keywords.workspace = true
atrium-xrpc.workspace = true
async-trait.workspace = true
http.workspace = true
regex.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_bytes.workspace = true
tokio = { workspace = true, optional = true }
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.bsky
.actor
.get_profile(atrium_api::app::bsky::actor::get_profile::Parameters {
actor: "bsky.app".into(),
actor: "bsky.app".parse()?,
})
.await?;
println!("{:?}", result);
Expand Down
14 changes: 7 additions & 7 deletions atrium-api/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ mod tests {
body.extend(serde_json::to_vec(
&crate::com::atproto::server::refresh_session::Output {
access_jwt: String::from("access"),
did: String::from("did"),
did: "did:web:example.com".parse().expect("valid"),
did_doc: None,
handle: String::from("handle"),
handle: "example.com".parse().expect("valid"),
refresh_jwt: String::from("refresh"),
},
)?);
Expand Down Expand Up @@ -187,11 +187,11 @@ mod tests {
fn session() -> Session {
Session {
access_jwt: String::from("access"),
did: String::from("did"),
did: "did:web:example.com".parse().expect("valid"),
did_doc: None,
email: None,
email_confirmed: None,
handle: String::from("handle"),
handle: "example.com".parse().expect("valid"),
refresh_jwt: String::from("refresh"),
}
}
Expand Down Expand Up @@ -266,7 +266,7 @@ mod tests {
.get_session()
.await
.expect("get session should be succeeded");
assert_eq!(output.did, "did");
assert_eq!(output.did.as_str(), "did:web:example.com");
}

#[tokio::test]
Expand Down Expand Up @@ -296,7 +296,7 @@ mod tests {
.get_session()
.await
.expect("get session should be succeeded");
assert_eq!(output.did, "did");
assert_eq!(output.did.as_str(), "did:web:example.com");
assert_eq!(
agent
.store
Expand Down Expand Up @@ -338,7 +338,7 @@ mod tests {
.expect("task should be successfully executed")
.as_ref()
.expect("get session should be succeeded");
assert_eq!(output.did, "did");
assert_eq!(output.did.as_str(), "did:web:example.com");
}
assert_eq!(
agent
Expand Down
12 changes: 6 additions & 6 deletions atrium-api/src/app/bsky/actor/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ pub struct ProfileView {
pub avatar: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub did: String,
pub did: crate::types::string::Did,
#[serde(skip_serializing_if = "Option::is_none")]
pub display_name: Option<String>,
pub handle: String,
pub handle: crate::types::string::Handle,
#[serde(skip_serializing_if = "Option::is_none")]
pub indexed_at: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -70,10 +70,10 @@ pub struct ProfileView {
pub struct ProfileViewBasic {
#[serde(skip_serializing_if = "Option::is_none")]
pub avatar: Option<String>,
pub did: String,
pub did: crate::types::string::Did,
#[serde(skip_serializing_if = "Option::is_none")]
pub display_name: Option<String>,
pub handle: String,
pub handle: crate::types::string::Handle,
#[serde(skip_serializing_if = "Option::is_none")]
pub labels: Option<Vec<crate::com::atproto::label::defs::Label>>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -88,14 +88,14 @@ pub struct ProfileViewDetailed {
pub banner: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub did: String,
pub did: crate::types::string::Did,
#[serde(skip_serializing_if = "Option::is_none")]
pub display_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub followers_count: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub follows_count: Option<i64>,
pub handle: String,
pub handle: crate::types::string::Handle,
#[serde(skip_serializing_if = "Option::is_none")]
pub indexed_at: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/actor/get_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Parameters {
pub actor: String,
pub actor: crate::types::string::AtIdentifier,
}
pub type Output = crate::app::bsky::actor::defs::ProfileViewDetailed;
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/actor/get_profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Parameters {
pub actors: Vec<String>,
pub actors: Vec<crate::types::string::AtIdentifier>,
}
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
Expand Down
4 changes: 2 additions & 2 deletions atrium-api/src/app/bsky/feed/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct BlockedAuthor {
pub did: String,
pub did: crate::types::string::Did,
#[serde(skip_serializing_if = "Option::is_none")]
pub viewer: Option<crate::app::bsky::actor::defs::ViewerState>,
}
Expand Down Expand Up @@ -34,7 +34,7 @@ pub struct GeneratorView {
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description_facets: Option<Vec<crate::app::bsky::richtext::facet::Main>>,
pub did: String,
pub did: crate::types::string::Did,
pub display_name: String,
pub indexed_at: String,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/feed/describe_feed_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Output {
pub did: String,
pub did: crate::types::string::Did,
pub feeds: Vec<Feed>,
#[serde(skip_serializing_if = "Option::is_none")]
pub links: Option<Links>,
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/feed/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Record {
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description_facets: Option<Vec<crate::app::bsky::richtext::facet::Main>>,
pub did: String,
pub did: crate::types::string::Did,
pub display_name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub labels: Option<RecordLabelsEnum>,
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/feed/get_actor_feeds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Parameters {
pub actor: String,
pub actor: crate::types::string::AtIdentifier,
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/feed/get_actor_likes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Parameters {
pub actor: String,
pub actor: crate::types::string::AtIdentifier,
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/feed/get_author_feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Parameters {
pub actor: String,
pub actor: crate::types::string::AtIdentifier,
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/graph/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
#[serde(rename_all = "camelCase")]
pub struct Record {
pub created_at: String,
pub subject: String,
pub subject: crate::types::string::Did,
}
4 changes: 2 additions & 2 deletions atrium-api/src/app/bsky/graph/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ pub struct Modlist;
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct NotFoundActor {
pub actor: String,
pub actor: crate::types::string::AtIdentifier,
pub not_found: bool,
}
///lists the bi-directional graph relationships between one actor (not indicated in the object), and the target actors (the DID included in the object)
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Relationship {
pub did: String,
pub did: crate::types::string::Did,
///if the actor is followed by this DID, contains the AT-URI of the follow record
#[serde(skip_serializing_if = "Option::is_none")]
pub followed_by: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/graph/follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
#[serde(rename_all = "camelCase")]
pub struct Record {
pub created_at: String,
pub subject: String,
pub subject: crate::types::string::Did,
}
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/graph/get_followers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Parameters {
pub actor: String,
pub actor: crate::types::string::AtIdentifier,
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/graph/get_follows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Parameters {
pub actor: String,
pub actor: crate::types::string::AtIdentifier,
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/graph/get_lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Parameters {
pub actor: String,
pub actor: crate::types::string::AtIdentifier,
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
6 changes: 3 additions & 3 deletions atrium-api/src/app/bsky/graph/get_relationships.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Parameters {
pub actor: String,
pub actor: crate::types::string::AtIdentifier,
#[serde(skip_serializing_if = "Option::is_none")]
pub others: Option<Vec<String>>,
pub others: Option<Vec<crate::types::string::AtIdentifier>>,
}
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Output {
#[serde(skip_serializing_if = "Option::is_none")]
pub actor: Option<String>,
pub actor: Option<crate::types::string::Did>,
pub relationships: Vec<OutputRelationshipsItem>,
}
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Parameters {
pub actor: String,
pub actor: crate::types::string::AtIdentifier,
}
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/graph/listitem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
pub struct Record {
pub created_at: String,
pub list: String,
pub subject: String,
pub subject: crate::types::string::Did,
}
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/graph/mute_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Input {
pub actor: String,
pub actor: crate::types::string::AtIdentifier,
}
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(tag = "error", content = "message")]
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/graph/unmute_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Input {
pub actor: String,
pub actor: crate::types::string::AtIdentifier,
}
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(tag = "error", content = "message")]
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/notification/register_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pub struct Input {
pub app_id: String,
pub platform: String,
pub service_did: String,
pub service_did: crate::types::string::Did,
pub token: String,
}
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/richtext/facet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct Link {
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Mention {
pub did: String,
pub did: crate::types::string::Did,
}
///A hashtag.
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion atrium-api/src/app/bsky/unspecced/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct SkeletonSearchActor {
pub did: String,
pub did: crate::types::string::Did,
}
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Input {
pub content_markdown: String,
///DID of the user who is creating the template.
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<String>,
pub created_by: Option<crate::types::string::Did>,
///Name of the template.
pub name: String,
///Subject of the message, used in emails.
Expand Down
Loading

0 comments on commit 6060a7c

Please sign in to comment.