From 527b9c86a54c4c1f7d28d68693a3dd2ca93176d4 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sat, 17 Feb 2024 22:57:41 +0000 Subject: [PATCH] Introduce types guaranteed to fit the range of each Lexicon integer --- atrium-api/CHANGELOG.md | 11 ++ atrium-api/src/app/bsky/actor/defs.rs | 8 +- .../src/app/bsky/actor/get_suggestions.rs | 2 +- .../src/app/bsky/actor/search_actors.rs | 2 +- .../app/bsky/actor/search_actors_typeahead.rs | 2 +- atrium-api/src/app/bsky/embed/images.rs | 4 +- atrium-api/src/app/bsky/feed/defs.rs | 8 +- .../src/app/bsky/feed/get_actor_feeds.rs | 2 +- .../src/app/bsky/feed/get_actor_likes.rs | 2 +- .../src/app/bsky/feed/get_author_feed.rs | 2 +- atrium-api/src/app/bsky/feed/get_feed.rs | 2 +- .../src/app/bsky/feed/get_feed_skeleton.rs | 2 +- atrium-api/src/app/bsky/feed/get_likes.rs | 2 +- atrium-api/src/app/bsky/feed/get_list_feed.rs | 2 +- .../src/app/bsky/feed/get_post_thread.rs | 4 +- .../src/app/bsky/feed/get_reposted_by.rs | 2 +- .../src/app/bsky/feed/get_suggested_feeds.rs | 2 +- atrium-api/src/app/bsky/feed/get_timeline.rs | 2 +- atrium-api/src/app/bsky/feed/post.rs | 4 +- atrium-api/src/app/bsky/feed/search_posts.rs | 4 +- atrium-api/src/app/bsky/graph/get_blocks.rs | 2 +- .../src/app/bsky/graph/get_followers.rs | 2 +- atrium-api/src/app/bsky/graph/get_follows.rs | 2 +- atrium-api/src/app/bsky/graph/get_list.rs | 2 +- .../src/app/bsky/graph/get_list_blocks.rs | 2 +- .../src/app/bsky/graph/get_list_mutes.rs | 2 +- atrium-api/src/app/bsky/graph/get_lists.rs | 2 +- atrium-api/src/app/bsky/graph/get_mutes.rs | 2 +- .../app/bsky/notification/get_unread_count.rs | 2 +- .../bsky/notification/list_notifications.rs | 2 +- atrium-api/src/app/bsky/richtext/facet.rs | 4 +- .../unspecced/get_popular_feed_generators.rs | 2 +- .../bsky/unspecced/search_actors_skeleton.rs | 4 +- .../bsky/unspecced/search_posts_skeleton.rs | 4 +- atrium-api/src/com/atproto/admin/defs.rs | 28 ++-- .../src/com/atproto/admin/get_invite_codes.rs | 2 +- .../com/atproto/admin/get_moderation_event.rs | 2 +- .../atproto/admin/query_moderation_events.rs | 2 +- .../admin/query_moderation_statuses.rs | 2 +- .../src/com/atproto/admin/search_repos.rs | 2 +- .../src/com/atproto/label/query_labels.rs | 2 +- .../src/com/atproto/label/subscribe_labels.rs | 4 +- .../com/atproto/moderation/create_report.rs | 2 +- .../src/com/atproto/repo/list_records.rs | 2 +- .../com/atproto/server/create_invite_code.rs | 2 +- .../com/atproto/server/create_invite_codes.rs | 4 +- atrium-api/src/com/atproto/server/defs.rs | 2 +- atrium-api/src/com/atproto/sync/list_blobs.rs | 2 +- atrium-api/src/com/atproto/sync/list_repos.rs | 2 +- .../src/com/atproto/sync/subscribe_repos.rs | 10 +- .../com/atproto/temp/check_signup_queue.rs | 4 +- .../src/com/atproto/temp/fetch_labels.rs | 4 +- atrium-api/src/types.rs | 3 + atrium-api/src/types/integer.rs | 128 ++++++++++++++++++ atrium-cli/src/runner.rs | 15 +- lexicon/atrium-codegen/src/token_stream.rs | 114 +++++++++++++++- lexicon/atrium-lex/src/lexicon.rs | 6 + 57 files changed, 353 insertions(+), 94 deletions(-) create mode 100644 atrium-api/src/types/integer.rs diff --git a/atrium-api/CHANGELOG.md b/atrium-api/CHANGELOG.md index 93d1cc23..fcc0ade7 100644 --- a/atrium-api/CHANGELOG.md +++ b/atrium-api/CHANGELOG.md @@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- `atrium_api::types`: + - `LimitedU8`, `LimitedNonZeroU8`, `BoundedU8` + - `LimitedU16`, `LimitedNonZeroU16`, `BoundedU16` + - `LimitedU32`, `LimitedNonZeroU32`, `BoundedU32` + - `LimitedU64`, `LimitedNonZeroU64`, `BoundedU64` + +### Changed +- All Lexicon integer fields now have a type that matches their minimum and maximum + accepted values, instead of `i32`. + ## [0.16.0](https://github.com/sugyan/atrium/compare/atrium-api-v0.15.0...atrium-api-v0.16.0) - 2024-02-09 ### Added diff --git a/atrium-api/src/app/bsky/actor/defs.rs b/atrium-api/src/app/bsky/actor/defs.rs index c6eaf5ca..4162b0d7 100644 --- a/atrium-api/src/app/bsky/actor/defs.rs +++ b/atrium-api/src/app/bsky/actor/defs.rs @@ -25,7 +25,7 @@ pub struct FeedViewPref { pub hide_replies: Option, ///Hide replies in the feed if they do not have this number of likes. #[serde(skip_serializing_if = "Option::is_none")] - pub hide_replies_by_like_count: Option, + pub hide_replies_by_like_count: Option, ///Hide replies in the feed if they are not by followed users. #[serde(skip_serializing_if = "Option::is_none")] pub hide_replies_by_unfollowed: Option, @@ -92,16 +92,16 @@ pub struct ProfileViewDetailed { #[serde(skip_serializing_if = "Option::is_none")] pub display_name: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub followers_count: Option, + pub followers_count: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub follows_count: Option, + pub follows_count: Option, pub handle: String, #[serde(skip_serializing_if = "Option::is_none")] pub indexed_at: Option, #[serde(skip_serializing_if = "Option::is_none")] pub labels: Option>, #[serde(skip_serializing_if = "Option::is_none")] - pub posts_count: Option, + pub posts_count: Option, #[serde(skip_serializing_if = "Option::is_none")] pub viewer: Option, } diff --git a/atrium-api/src/app/bsky/actor/get_suggestions.rs b/atrium-api/src/app/bsky/actor/get_suggestions.rs index 3628e2b9..03d58570 100644 --- a/atrium-api/src/app/bsky/actor/get_suggestions.rs +++ b/atrium-api/src/app/bsky/actor/get_suggestions.rs @@ -6,7 +6,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/app/bsky/actor/search_actors.rs b/atrium-api/src/app/bsky/actor/search_actors.rs index bcb1d029..657d8a2d 100644 --- a/atrium-api/src/app/bsky/actor/search_actors.rs +++ b/atrium-api/src/app/bsky/actor/search_actors.rs @@ -6,7 +6,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, ///Search query string. Syntax, phrase, boolean, and faceting is unspecified, but Lucene query syntax is recommended. #[serde(skip_serializing_if = "Option::is_none")] pub q: Option, diff --git a/atrium-api/src/app/bsky/actor/search_actors_typeahead.rs b/atrium-api/src/app/bsky/actor/search_actors_typeahead.rs index 6f9b1191..74d4652e 100644 --- a/atrium-api/src/app/bsky/actor/search_actors_typeahead.rs +++ b/atrium-api/src/app/bsky/actor/search_actors_typeahead.rs @@ -4,7 +4,7 @@ #[serde(rename_all = "camelCase")] pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, ///Search query prefix; not a full query string. #[serde(skip_serializing_if = "Option::is_none")] pub q: Option, diff --git a/atrium-api/src/app/bsky/embed/images.rs b/atrium-api/src/app/bsky/embed/images.rs index bd0b63c1..d9156b52 100644 --- a/atrium-api/src/app/bsky/embed/images.rs +++ b/atrium-api/src/app/bsky/embed/images.rs @@ -10,8 +10,8 @@ pub struct Main { #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct AspectRatio { - pub height: i32, - pub width: i32, + pub height: core::num::NonZeroU64, + pub width: core::num::NonZeroU64, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/app/bsky/feed/defs.rs b/atrium-api/src/app/bsky/feed/defs.rs index 2cbd14dc..8f0efaf8 100644 --- a/atrium-api/src/app/bsky/feed/defs.rs +++ b/atrium-api/src/app/bsky/feed/defs.rs @@ -38,7 +38,7 @@ pub struct GeneratorView { pub display_name: String, pub indexed_at: String, #[serde(skip_serializing_if = "Option::is_none")] - pub like_count: Option, + pub like_count: Option, pub uri: String, #[serde(skip_serializing_if = "Option::is_none")] pub viewer: Option, @@ -66,12 +66,12 @@ pub struct PostView { #[serde(skip_serializing_if = "Option::is_none")] pub labels: Option>, #[serde(skip_serializing_if = "Option::is_none")] - pub like_count: Option, + pub like_count: Option, pub record: crate::records::Record, #[serde(skip_serializing_if = "Option::is_none")] - pub reply_count: Option, + pub reply_count: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub repost_count: Option, + pub repost_count: Option, #[serde(skip_serializing_if = "Option::is_none")] pub threadgate: Option, pub uri: String, diff --git a/atrium-api/src/app/bsky/feed/get_actor_feeds.rs b/atrium-api/src/app/bsky/feed/get_actor_feeds.rs index 8db6228e..b52de815 100644 --- a/atrium-api/src/app/bsky/feed/get_actor_feeds.rs +++ b/atrium-api/src/app/bsky/feed/get_actor_feeds.rs @@ -7,7 +7,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/app/bsky/feed/get_actor_likes.rs b/atrium-api/src/app/bsky/feed/get_actor_likes.rs index fb07aca2..acb015f6 100644 --- a/atrium-api/src/app/bsky/feed/get_actor_likes.rs +++ b/atrium-api/src/app/bsky/feed/get_actor_likes.rs @@ -7,7 +7,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/app/bsky/feed/get_author_feed.rs b/atrium-api/src/app/bsky/feed/get_author_feed.rs index 93857868..e91d011f 100644 --- a/atrium-api/src/app/bsky/feed/get_author_feed.rs +++ b/atrium-api/src/app/bsky/feed/get_author_feed.rs @@ -9,7 +9,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub filter: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/app/bsky/feed/get_feed.rs b/atrium-api/src/app/bsky/feed/get_feed.rs index 260d1350..5cddcf36 100644 --- a/atrium-api/src/app/bsky/feed/get_feed.rs +++ b/atrium-api/src/app/bsky/feed/get_feed.rs @@ -7,7 +7,7 @@ pub struct Parameters { pub cursor: Option, pub feed: String, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/app/bsky/feed/get_feed_skeleton.rs b/atrium-api/src/app/bsky/feed/get_feed_skeleton.rs index 8463e59f..b1430741 100644 --- a/atrium-api/src/app/bsky/feed/get_feed_skeleton.rs +++ b/atrium-api/src/app/bsky/feed/get_feed_skeleton.rs @@ -7,7 +7,7 @@ pub struct Parameters { pub cursor: Option, pub feed: String, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/app/bsky/feed/get_likes.rs b/atrium-api/src/app/bsky/feed/get_likes.rs index f047e9ad..392415a3 100644 --- a/atrium-api/src/app/bsky/feed/get_likes.rs +++ b/atrium-api/src/app/bsky/feed/get_likes.rs @@ -8,7 +8,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, pub uri: String, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] diff --git a/atrium-api/src/app/bsky/feed/get_list_feed.rs b/atrium-api/src/app/bsky/feed/get_list_feed.rs index b5b8556c..fb0d2b16 100644 --- a/atrium-api/src/app/bsky/feed/get_list_feed.rs +++ b/atrium-api/src/app/bsky/feed/get_list_feed.rs @@ -6,7 +6,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, pub list: String, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] diff --git a/atrium-api/src/app/bsky/feed/get_post_thread.rs b/atrium-api/src/app/bsky/feed/get_post_thread.rs index a4504520..c68b757d 100644 --- a/atrium-api/src/app/bsky/feed/get_post_thread.rs +++ b/atrium-api/src/app/bsky/feed/get_post_thread.rs @@ -4,9 +4,9 @@ #[serde(rename_all = "camelCase")] pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] - pub depth: Option, + pub depth: Option>, #[serde(skip_serializing_if = "Option::is_none")] - pub parent_height: Option, + pub parent_height: Option>, pub uri: String, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] diff --git a/atrium-api/src/app/bsky/feed/get_reposted_by.rs b/atrium-api/src/app/bsky/feed/get_reposted_by.rs index 2a06b484..b56d6027 100644 --- a/atrium-api/src/app/bsky/feed/get_reposted_by.rs +++ b/atrium-api/src/app/bsky/feed/get_reposted_by.rs @@ -8,7 +8,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, pub uri: String, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] diff --git a/atrium-api/src/app/bsky/feed/get_suggested_feeds.rs b/atrium-api/src/app/bsky/feed/get_suggested_feeds.rs index a9682174..00db0458 100644 --- a/atrium-api/src/app/bsky/feed/get_suggested_feeds.rs +++ b/atrium-api/src/app/bsky/feed/get_suggested_feeds.rs @@ -6,7 +6,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/app/bsky/feed/get_timeline.rs b/atrium-api/src/app/bsky/feed/get_timeline.rs index 1624f04b..43e94e6a 100644 --- a/atrium-api/src/app/bsky/feed/get_timeline.rs +++ b/atrium-api/src/app/bsky/feed/get_timeline.rs @@ -8,7 +8,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/app/bsky/feed/post.rs b/atrium-api/src/app/bsky/feed/post.rs index 04575c74..91b76c0e 100644 --- a/atrium-api/src/app/bsky/feed/post.rs +++ b/atrium-api/src/app/bsky/feed/post.rs @@ -41,8 +41,8 @@ pub struct ReplyRef { #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct TextSlice { - pub end: i32, - pub start: i32, + pub end: usize, + pub start: usize, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(tag = "$type")] diff --git a/atrium-api/src/app/bsky/feed/search_posts.rs b/atrium-api/src/app/bsky/feed/search_posts.rs index 39cfc7a2..416c0b9a 100644 --- a/atrium-api/src/app/bsky/feed/search_posts.rs +++ b/atrium-api/src/app/bsky/feed/search_posts.rs @@ -7,7 +7,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, ///Search query string; syntax, phrase, boolean, and faceting is unspecified, but Lucene query syntax is recommended. pub q: String, } @@ -18,7 +18,7 @@ pub struct Output { pub cursor: Option, ///Count of search hits. Optional, may be rounded/truncated, and may not be possible to paginate through all hits. #[serde(skip_serializing_if = "Option::is_none")] - pub hits_total: Option, + pub hits_total: Option, pub posts: Vec, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] diff --git a/atrium-api/src/app/bsky/graph/get_blocks.rs b/atrium-api/src/app/bsky/graph/get_blocks.rs index 089c2da0..398fdd91 100644 --- a/atrium-api/src/app/bsky/graph/get_blocks.rs +++ b/atrium-api/src/app/bsky/graph/get_blocks.rs @@ -6,7 +6,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/app/bsky/graph/get_followers.rs b/atrium-api/src/app/bsky/graph/get_followers.rs index 0d107e4a..d46fed23 100644 --- a/atrium-api/src/app/bsky/graph/get_followers.rs +++ b/atrium-api/src/app/bsky/graph/get_followers.rs @@ -7,7 +7,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/app/bsky/graph/get_follows.rs b/atrium-api/src/app/bsky/graph/get_follows.rs index 7bd9e736..c2864897 100644 --- a/atrium-api/src/app/bsky/graph/get_follows.rs +++ b/atrium-api/src/app/bsky/graph/get_follows.rs @@ -7,7 +7,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/app/bsky/graph/get_list.rs b/atrium-api/src/app/bsky/graph/get_list.rs index 9cd04232..f32c8704 100644 --- a/atrium-api/src/app/bsky/graph/get_list.rs +++ b/atrium-api/src/app/bsky/graph/get_list.rs @@ -6,7 +6,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, pub list: String, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] diff --git a/atrium-api/src/app/bsky/graph/get_list_blocks.rs b/atrium-api/src/app/bsky/graph/get_list_blocks.rs index 45f60436..85b2faa9 100644 --- a/atrium-api/src/app/bsky/graph/get_list_blocks.rs +++ b/atrium-api/src/app/bsky/graph/get_list_blocks.rs @@ -6,7 +6,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/app/bsky/graph/get_list_mutes.rs b/atrium-api/src/app/bsky/graph/get_list_mutes.rs index 47ba799b..ad826ec9 100644 --- a/atrium-api/src/app/bsky/graph/get_list_mutes.rs +++ b/atrium-api/src/app/bsky/graph/get_list_mutes.rs @@ -6,7 +6,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/app/bsky/graph/get_lists.rs b/atrium-api/src/app/bsky/graph/get_lists.rs index 910faa83..71e8e4a0 100644 --- a/atrium-api/src/app/bsky/graph/get_lists.rs +++ b/atrium-api/src/app/bsky/graph/get_lists.rs @@ -7,7 +7,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/app/bsky/graph/get_mutes.rs b/atrium-api/src/app/bsky/graph/get_mutes.rs index 224f284c..76ed50c8 100644 --- a/atrium-api/src/app/bsky/graph/get_mutes.rs +++ b/atrium-api/src/app/bsky/graph/get_mutes.rs @@ -6,7 +6,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/app/bsky/notification/get_unread_count.rs b/atrium-api/src/app/bsky/notification/get_unread_count.rs index 9b730061..53032d2d 100644 --- a/atrium-api/src/app/bsky/notification/get_unread_count.rs +++ b/atrium-api/src/app/bsky/notification/get_unread_count.rs @@ -9,7 +9,7 @@ pub struct Parameters { #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct Output { - pub count: i32, + pub count: i64, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(tag = "error", content = "message")] diff --git a/atrium-api/src/app/bsky/notification/list_notifications.rs b/atrium-api/src/app/bsky/notification/list_notifications.rs index f0cbc0f9..c7a01b71 100644 --- a/atrium-api/src/app/bsky/notification/list_notifications.rs +++ b/atrium-api/src/app/bsky/notification/list_notifications.rs @@ -6,7 +6,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, #[serde(skip_serializing_if = "Option::is_none")] pub seen_at: Option, } diff --git a/atrium-api/src/app/bsky/richtext/facet.rs b/atrium-api/src/app/bsky/richtext/facet.rs index e5431641..b0e54935 100644 --- a/atrium-api/src/app/bsky/richtext/facet.rs +++ b/atrium-api/src/app/bsky/richtext/facet.rs @@ -10,8 +10,8 @@ pub struct Main { #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct ByteSlice { - pub byte_end: i32, - pub byte_start: i32, + pub byte_end: usize, + pub byte_start: usize, } ///A facet feature for links. #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] diff --git a/atrium-api/src/app/bsky/unspecced/get_popular_feed_generators.rs b/atrium-api/src/app/bsky/unspecced/get_popular_feed_generators.rs index a87cab07..9bc9ab35 100644 --- a/atrium-api/src/app/bsky/unspecced/get_popular_feed_generators.rs +++ b/atrium-api/src/app/bsky/unspecced/get_popular_feed_generators.rs @@ -6,7 +6,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, #[serde(skip_serializing_if = "Option::is_none")] pub query: Option, } diff --git a/atrium-api/src/app/bsky/unspecced/search_actors_skeleton.rs b/atrium-api/src/app/bsky/unspecced/search_actors_skeleton.rs index 4cb1b0dd..1d484901 100644 --- a/atrium-api/src/app/bsky/unspecced/search_actors_skeleton.rs +++ b/atrium-api/src/app/bsky/unspecced/search_actors_skeleton.rs @@ -7,7 +7,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, ///Search query string; syntax, phrase, boolean, and faceting is unspecified, but Lucene query syntax is recommended. For typeahead search, only simple term match is supported, not full syntax. pub q: String, ///If true, acts as fast/simple 'typeahead' query. @@ -22,7 +22,7 @@ pub struct Output { pub cursor: Option, ///Count of search hits. Optional, may be rounded/truncated, and may not be possible to paginate through all hits. #[serde(skip_serializing_if = "Option::is_none")] - pub hits_total: Option, + pub hits_total: Option, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(tag = "error", content = "message")] diff --git a/atrium-api/src/app/bsky/unspecced/search_posts_skeleton.rs b/atrium-api/src/app/bsky/unspecced/search_posts_skeleton.rs index 47c7fa7d..76723d5e 100644 --- a/atrium-api/src/app/bsky/unspecced/search_posts_skeleton.rs +++ b/atrium-api/src/app/bsky/unspecced/search_posts_skeleton.rs @@ -7,7 +7,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, ///Search query string; syntax, phrase, boolean, and faceting is unspecified, but Lucene query syntax is recommended. pub q: String, } @@ -18,7 +18,7 @@ pub struct Output { pub cursor: Option, ///Count of search hits. Optional, may be rounded/truncated, and may not be possible to paginate through all hits. #[serde(skip_serializing_if = "Option::is_none")] - pub hits_total: Option, + pub hits_total: Option, pub posts: Vec, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] diff --git a/atrium-api/src/com/atproto/admin/defs.rs b/atrium-api/src/com/atproto/admin/defs.rs index 6de4b83a..2d653946 100644 --- a/atrium-api/src/com/atproto/admin/defs.rs +++ b/atrium-api/src/com/atproto/admin/defs.rs @@ -31,7 +31,7 @@ pub struct BlobView { pub mime_type: String, #[serde(skip_serializing_if = "Option::is_none")] pub moderation: Option, - pub size: i32, + pub size: i64, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] @@ -53,8 +53,8 @@ pub struct CommunicationTemplateView { #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct ImageDetails { - pub height: i32, - pub width: i32, + pub height: i64, + pub width: i64, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] @@ -103,7 +103,7 @@ pub struct ModEventMute { #[serde(skip_serializing_if = "Option::is_none")] pub comment: Option, ///Indicates how long the subject should remain muted. - pub duration_in_hours: i32, + pub duration_in_hours: i64, } ///Report a subject #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] @@ -137,7 +137,7 @@ pub struct ModEventTakedown { pub comment: Option, ///Indicates how long the takedown should be in effect before automatically expiring. #[serde(skip_serializing_if = "Option::is_none")] - pub duration_in_hours: Option, + pub duration_in_hours: Option, } ///Unmute action on a subject #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] @@ -155,7 +155,7 @@ pub struct ModEventView { #[serde(skip_serializing_if = "Option::is_none")] pub creator_handle: Option, pub event: ModEventViewEventEnum, - pub id: i32, + pub id: i64, pub subject: ModEventViewSubjectEnum, pub subject_blob_cids: Vec, #[serde(skip_serializing_if = "Option::is_none")] @@ -167,7 +167,7 @@ pub struct ModEventViewDetail { pub created_at: String, pub created_by: String, pub event: ModEventViewDetailEventEnum, - pub id: i32, + pub id: i64, pub subject: ModEventViewDetailSubjectEnum, pub subject_blobs: Vec, } @@ -276,10 +276,10 @@ pub struct ReportView { #[serde(skip_serializing_if = "Option::is_none")] pub comment: Option, pub created_at: String, - pub id: i32, + pub id: i64, pub reason_type: crate::com::atproto::moderation::defs::ReasonType, pub reported_by: String, - pub resolved_by_action_ids: Vec, + pub resolved_by_action_ids: Vec, pub subject: ReportViewSubjectEnum, #[serde(skip_serializing_if = "Option::is_none")] pub subject_repo_handle: Option, @@ -290,7 +290,7 @@ pub struct ReportViewDetail { #[serde(skip_serializing_if = "Option::is_none")] pub comment: Option, pub created_at: String, - pub id: i32, + pub id: i64, pub reason_type: crate::com::atproto::moderation::defs::ReasonType, pub reported_by: String, pub resolved_by_actions: Vec, @@ -323,7 +323,7 @@ pub struct SubjectStatusView { pub comment: Option, ///Timestamp referencing the first moderation status impacting event was emitted on the subject pub created_at: String, - pub id: i32, + pub id: i64, ///Timestamp referencing when the author of the subject appealed a moderation action #[serde(skip_serializing_if = "Option::is_none")] pub last_appealed_at: Option, @@ -351,9 +351,9 @@ pub struct SubjectStatusView { #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct VideoDetails { - pub height: i32, - pub length: i32, - pub width: i32, + pub height: i64, + pub length: i64, + pub width: i64, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(tag = "$type")] diff --git a/atrium-api/src/com/atproto/admin/get_invite_codes.rs b/atrium-api/src/com/atproto/admin/get_invite_codes.rs index 664341c3..a7f69188 100644 --- a/atrium-api/src/com/atproto/admin/get_invite_codes.rs +++ b/atrium-api/src/com/atproto/admin/get_invite_codes.rs @@ -6,7 +6,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, #[serde(skip_serializing_if = "Option::is_none")] pub sort: Option, } diff --git a/atrium-api/src/com/atproto/admin/get_moderation_event.rs b/atrium-api/src/com/atproto/admin/get_moderation_event.rs index c1023b5d..d9b34361 100644 --- a/atrium-api/src/com/atproto/admin/get_moderation_event.rs +++ b/atrium-api/src/com/atproto/admin/get_moderation_event.rs @@ -3,7 +3,7 @@ #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct Parameters { - pub id: i32, + pub id: i64, } pub type Output = crate::com::atproto::admin::defs::ModEventViewDetail; #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] diff --git a/atrium-api/src/com/atproto/admin/query_moderation_events.rs b/atrium-api/src/com/atproto/admin/query_moderation_events.rs index f5e41ad2..c26208d0 100644 --- a/atrium-api/src/com/atproto/admin/query_moderation_events.rs +++ b/atrium-api/src/com/atproto/admin/query_moderation_events.rs @@ -26,7 +26,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub include_all_user_records: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, ///If specified, only events where all of these labels were removed are returned #[serde(skip_serializing_if = "Option::is_none")] pub removed_labels: Option>, diff --git a/atrium-api/src/com/atproto/admin/query_moderation_statuses.rs b/atrium-api/src/com/atproto/admin/query_moderation_statuses.rs index 9797bfe5..8bd22b46 100644 --- a/atrium-api/src/com/atproto/admin/query_moderation_statuses.rs +++ b/atrium-api/src/com/atproto/admin/query_moderation_statuses.rs @@ -20,7 +20,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub last_reviewed_by: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, ///Search subjects reported after a given timestamp #[serde(skip_serializing_if = "Option::is_none")] pub reported_after: Option, diff --git a/atrium-api/src/com/atproto/admin/search_repos.rs b/atrium-api/src/com/atproto/admin/search_repos.rs index c9f483b5..95bb7709 100644 --- a/atrium-api/src/com/atproto/admin/search_repos.rs +++ b/atrium-api/src/com/atproto/admin/search_repos.rs @@ -6,7 +6,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, #[serde(skip_serializing_if = "Option::is_none")] pub q: Option, ///DEPRECATED: use 'q' instead diff --git a/atrium-api/src/com/atproto/label/query_labels.rs b/atrium-api/src/com/atproto/label/query_labels.rs index feffe382..16382829 100644 --- a/atrium-api/src/com/atproto/label/query_labels.rs +++ b/atrium-api/src/com/atproto/label/query_labels.rs @@ -6,7 +6,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, ///Optional list of label sources (DIDs) to filter on. #[serde(skip_serializing_if = "Option::is_none")] pub sources: Option>, diff --git a/atrium-api/src/com/atproto/label/subscribe_labels.rs b/atrium-api/src/com/atproto/label/subscribe_labels.rs index eb6d4806..374fa087 100644 --- a/atrium-api/src/com/atproto/label/subscribe_labels.rs +++ b/atrium-api/src/com/atproto/label/subscribe_labels.rs @@ -6,7 +6,7 @@ pub const NSID: &str = "com.atproto.label.subscribeLabels"; pub struct Parameters { ///The last known event to backfill from. #[serde(skip_serializing_if = "Option::is_none")] - pub cursor: Option, + pub cursor: Option, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(tag = "error", content = "message")] @@ -24,7 +24,7 @@ pub struct Info { #[serde(rename_all = "camelCase")] pub struct Labels { pub labels: Vec, - pub seq: i32, + pub seq: i64, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(tag = "$type")] diff --git a/atrium-api/src/com/atproto/moderation/create_report.rs b/atrium-api/src/com/atproto/moderation/create_report.rs index 430d4737..b1886c9d 100644 --- a/atrium-api/src/com/atproto/moderation/create_report.rs +++ b/atrium-api/src/com/atproto/moderation/create_report.rs @@ -12,7 +12,7 @@ pub struct Input { #[serde(rename_all = "camelCase")] pub struct Output { pub created_at: String, - pub id: i32, + pub id: i64, #[serde(skip_serializing_if = "Option::is_none")] pub reason: Option, pub reason_type: crate::com::atproto::moderation::defs::ReasonType, diff --git a/atrium-api/src/com/atproto/repo/list_records.rs b/atrium-api/src/com/atproto/repo/list_records.rs index 458641d0..08394c5a 100644 --- a/atrium-api/src/com/atproto/repo/list_records.rs +++ b/atrium-api/src/com/atproto/repo/list_records.rs @@ -9,7 +9,7 @@ pub struct Parameters { pub cursor: Option, ///The number of records to return. #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, ///The handle or DID of the repo. pub repo: String, ///Flag to reverse the order of the returned records. diff --git a/atrium-api/src/com/atproto/server/create_invite_code.rs b/atrium-api/src/com/atproto/server/create_invite_code.rs index b8d6ec96..f499065c 100644 --- a/atrium-api/src/com/atproto/server/create_invite_code.rs +++ b/atrium-api/src/com/atproto/server/create_invite_code.rs @@ -5,7 +5,7 @@ pub struct Input { #[serde(skip_serializing_if = "Option::is_none")] pub for_account: Option, - pub use_count: i32, + pub use_count: i64, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/com/atproto/server/create_invite_codes.rs b/atrium-api/src/com/atproto/server/create_invite_codes.rs index 2ed001f3..76f74dde 100644 --- a/atrium-api/src/com/atproto/server/create_invite_codes.rs +++ b/atrium-api/src/com/atproto/server/create_invite_codes.rs @@ -3,10 +3,10 @@ #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct Input { - pub code_count: i32, + pub code_count: i64, #[serde(skip_serializing_if = "Option::is_none")] pub for_accounts: Option>, - pub use_count: i32, + pub use_count: i64, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/com/atproto/server/defs.rs b/atrium-api/src/com/atproto/server/defs.rs index 7e488fbe..1c45e02a 100644 --- a/atrium-api/src/com/atproto/server/defs.rs +++ b/atrium-api/src/com/atproto/server/defs.rs @@ -3,7 +3,7 @@ #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct InviteCode { - pub available: i32, + pub available: i64, pub code: String, pub created_at: String, pub created_by: String, diff --git a/atrium-api/src/com/atproto/sync/list_blobs.rs b/atrium-api/src/com/atproto/sync/list_blobs.rs index b8c9fc83..2c837bfd 100644 --- a/atrium-api/src/com/atproto/sync/list_blobs.rs +++ b/atrium-api/src/com/atproto/sync/list_blobs.rs @@ -8,7 +8,7 @@ pub struct Parameters { ///The DID of the repo. pub did: String, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, ///Optional revision of the repo to list blobs since. #[serde(skip_serializing_if = "Option::is_none")] pub since: Option, diff --git a/atrium-api/src/com/atproto/sync/list_repos.rs b/atrium-api/src/com/atproto/sync/list_repos.rs index 85ccc8c6..3847403b 100644 --- a/atrium-api/src/com/atproto/sync/list_repos.rs +++ b/atrium-api/src/com/atproto/sync/list_repos.rs @@ -6,7 +6,7 @@ pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] pub cursor: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/com/atproto/sync/subscribe_repos.rs b/atrium-api/src/com/atproto/sync/subscribe_repos.rs index 3f84d3de..a123efc3 100644 --- a/atrium-api/src/com/atproto/sync/subscribe_repos.rs +++ b/atrium-api/src/com/atproto/sync/subscribe_repos.rs @@ -6,7 +6,7 @@ pub const NSID: &str = "com.atproto.sync.subscribeRepos"; pub struct Parameters { ///The last known event to backfill from. #[serde(skip_serializing_if = "Option::is_none")] - pub cursor: Option, + pub cursor: Option, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(tag = "error", content = "message")] @@ -29,7 +29,7 @@ pub struct Commit { pub repo: String, ///The rev of the emitted commit. pub rev: String, - pub seq: i32, + pub seq: i64, ///The rev of the last emitted commit from this repo. #[serde(skip_serializing_if = "Option::is_none")] pub since: Option, @@ -41,7 +41,7 @@ pub struct Commit { pub struct Handle { pub did: String, pub handle: String, - pub seq: i32, + pub seq: i64, pub time: String, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] @@ -57,7 +57,7 @@ pub struct Migrate { pub did: String, #[serde(skip_serializing_if = "Option::is_none")] pub migrate_to: Option, - pub seq: i32, + pub seq: i64, pub time: String, } ///A repo operation, ie a write of a single record. For creates and updates, CID is the record's CID as of this operation. For deletes, it's null. @@ -73,7 +73,7 @@ pub struct RepoOp { #[serde(rename_all = "camelCase")] pub struct Tombstone { pub did: String, - pub seq: i32, + pub seq: i64, pub time: String, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] diff --git a/atrium-api/src/com/atproto/temp/check_signup_queue.rs b/atrium-api/src/com/atproto/temp/check_signup_queue.rs index d614f5db..ae1cf572 100644 --- a/atrium-api/src/com/atproto/temp/check_signup_queue.rs +++ b/atrium-api/src/com/atproto/temp/check_signup_queue.rs @@ -5,9 +5,9 @@ pub struct Output { pub activated: bool, #[serde(skip_serializing_if = "Option::is_none")] - pub estimated_time_ms: Option, + pub estimated_time_ms: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub place_in_queue: Option, + pub place_in_queue: Option, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(tag = "error", content = "message")] diff --git a/atrium-api/src/com/atproto/temp/fetch_labels.rs b/atrium-api/src/com/atproto/temp/fetch_labels.rs index c8d908ab..70b55e2d 100644 --- a/atrium-api/src/com/atproto/temp/fetch_labels.rs +++ b/atrium-api/src/com/atproto/temp/fetch_labels.rs @@ -4,9 +4,9 @@ #[serde(rename_all = "camelCase")] pub struct Parameters { #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + pub limit: Option>, #[serde(skip_serializing_if = "Option::is_none")] - pub since: Option, + pub since: Option, } #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/atrium-api/src/types.rs b/atrium-api/src/types.rs index 5e0c6b12..726320f8 100644 --- a/atrium-api/src/types.rs +++ b/atrium-api/src/types.rs @@ -11,6 +11,9 @@ pub use cid_link_ipld::CidLink; #[cfg(not(feature = "dag-cbor"))] pub use cid_link_json::CidLink; +mod integer; +pub use integer::*; + /// Definitions for Blob types. /// Usually a map with `$type` is used, but deprecated legacy formats are also supported for parsing. /// diff --git a/atrium-api/src/types/integer.rs b/atrium-api/src/types/integer.rs new file mode 100644 index 00000000..7d4fe7cb --- /dev/null +++ b/atrium-api/src/types/integer.rs @@ -0,0 +1,128 @@ +//! Lexicon integer types with minimum or maximum acceptable values. + +use std::num::{NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8}; + +use serde::{de::Error, Deserialize}; + +macro_rules! uint { + ($primitive:ident, $nz:ident, $lim:ident, $lim_nz:ident, $bounded:ident) => { + /// An unsigned integer with a maximum value of `MAX`. + #[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize)] + #[repr(transparent)] + #[serde(transparent)] + pub struct $lim($primitive); + + impl $lim { + fn new(value: $primitive) -> Result { + if value > MAX { + Err(format!("value is greater than {}", MAX)) + } else { + Ok(Self(value)) + } + } + } + + impl TryFrom<$primitive> for $lim { + type Error = String; + + fn try_from(value: $primitive) -> Result { + Self::new(value) + } + } + + impl<'de, const MAX: $primitive> Deserialize<'de> for $lim { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + let value = Deserialize::deserialize(deserializer)?; + Self::new(value).map_err(D::Error::custom) + } + } + + /// An unsigned integer with a minimum value of 1 and a maximum value of `MAX`. + #[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize)] + #[repr(transparent)] + #[serde(transparent)] + pub struct $lim_nz($nz); + + impl $lim_nz { + fn new(value: $primitive) -> Result { + if value > MAX { + Err(format!("value is greater than {}", MAX)) + } else if let Some(value) = $nz::new(value) { + Ok(Self(value)) + } else { + Err("value is zero".into()) + } + } + } + + impl TryFrom<$primitive> for $lim_nz { + type Error = String; + + fn try_from(value: $primitive) -> Result { + Self::new(value) + } + } + + impl<'de, const MAX: $primitive> Deserialize<'de> for $lim_nz { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + let value = Deserialize::deserialize(deserializer)?; + Self::new(value).map_err(D::Error::custom) + } + } + + /// An unsigned integer with a minimum value of `MIN` and a maximum value of `MAX`. + /// + /// `MIN` must be non-zero. + #[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize)] + #[repr(transparent)] + #[serde(transparent)] + pub struct $bounded($nz); + + impl $bounded { + fn new(value: $primitive) -> Result { + if value < MIN { + Err(format!("value is less than {}", MIN)) + } else if value > MAX { + Err(format!("value is greater than {}", MAX)) + } else if let Some(value) = $nz::new(value) { + Ok(Self(value)) + } else { + Err("value is zero".into()) + } + } + } + + impl TryFrom<$primitive> + for $bounded + { + type Error = String; + + fn try_from(value: $primitive) -> Result { + Self::new(value) + } + } + + impl<'de, const MIN: $primitive, const MAX: $primitive> Deserialize<'de> + for $bounded + { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + let value = Deserialize::deserialize(deserializer)?; + Self::new(value).map_err(D::Error::custom) + } + } + }; +} + +uint!(u8, NonZeroU8, LimitedU8, LimitedNonZeroU8, BoundedU8); +uint!(u16, NonZeroU16, LimitedU16, LimitedNonZeroU16, BoundedU16); +uint!(u32, NonZeroU32, LimitedU32, LimitedNonZeroU32, BoundedU32); +uint!(u64, NonZeroU64, LimitedU64, LimitedNonZeroU64, BoundedU64); diff --git a/atrium-cli/src/runner.rs b/atrium-cli/src/runner.rs index b7b71857..c91c4871 100644 --- a/atrium-cli/src/runner.rs +++ b/atrium-cli/src/runner.rs @@ -36,6 +36,7 @@ impl Runner { }) } pub async fn run(&self, command: Command) { + let limit = 10.try_into().expect("within limit"); match command { Command::Login(args) => { let result = self.agent.login(args.identifier, args.password).await; @@ -59,7 +60,7 @@ impl Runner { .get_timeline(atrium_api::app::bsky::feed::get_timeline::Parameters { algorithm: None, cursor: None, - limit: Some(10), + limit: Some(limit), }) .await, ); @@ -76,7 +77,7 @@ impl Runner { actor: args.actor.or(self.handle.clone()).unwrap(), cursor: None, filter: None, - limit: Some(10), + limit: Some(limit), }) .await, ); @@ -92,7 +93,7 @@ impl Runner { .get_likes(atrium_api::app::bsky::feed::get_likes::Parameters { cid: None, cursor: None, - limit: Some(10), + limit: Some(limit), uri: args.uri.to_string(), }) .await, @@ -109,7 +110,7 @@ impl Runner { .get_reposted_by(atrium_api::app::bsky::feed::get_reposted_by::Parameters { cid: None, cursor: None, - limit: Some(10), + limit: Some(limit), uri: args.uri.to_string(), }) .await, @@ -126,7 +127,7 @@ impl Runner { .get_follows(atrium_api::app::bsky::graph::get_follows::Parameters { actor: args.actor.or(self.handle.clone()).unwrap(), cursor: None, - limit: Some(10), + limit: Some(limit), }) .await, ); @@ -142,7 +143,7 @@ impl Runner { .get_followers(atrium_api::app::bsky::graph::get_followers::Parameters { actor: args.actor.or(self.handle.clone()).unwrap(), cursor: None, - limit: Some(10), + limit: Some(limit), }) .await, ); @@ -172,7 +173,7 @@ impl Runner { .list_notifications( atrium_api::app::bsky::notification::list_notifications::Parameters { cursor: None, - limit: Some(10), + limit: Some(limit), seen_at: None, }, ) diff --git a/lexicon/atrium-codegen/src/token_stream.rs b/lexicon/atrium-codegen/src/token_stream.rs index bb5d7c18..e1480dc4 100644 --- a/lexicon/atrium-codegen/src/token_stream.rs +++ b/lexicon/atrium-codegen/src/token_stream.rs @@ -372,8 +372,118 @@ fn boolean_type(boolean: &LexBoolean) -> Result<(TokenStream, TokenStream)> { fn integer_type(integer: &LexInteger) -> Result<(TokenStream, TokenStream)> { let description = description(&integer.description); - // TODO: usize? - Ok((description, quote!(i32))) + let typ = match integer.minimum { + // If the minimum acceptable value is 0, use the unsigned integer primitives, with + // newtype wrappers enforcing the maximum acceptable value if relevant. + Some(0) => match integer.maximum { + // If a maximum acceptable value is specified, use the smallest fixed-width + // unsigned type that can fit all acceptable values. + Some(max) => match max { + 0x0000_0000..=0x0000_00fe => { + let max = max as u8; + quote!(crate::types::LimitedU8<#max>) + } + 0x0000_00ff => quote!(u8), + 0x0000_0100..=0x0000_fffe => { + let max = max as u16; + quote!(crate::types::LimitedU16<#max>) + } + 0x0000_ffff => quote!(u16), + 0x0001_0000..=0xffff_fffe => { + let max = max as u32; + quote!(crate::types::LimitedU32<#max>) + } + 0xffff_ffff => quote!(u32), + _ => { + let max = max as u64; + quote!(crate::types::LimitedU64<#max>) + } + }, + // If no maximum acceptable value is specified, assume that the integer might + // be an index into (or the length of) something stored in memory (e.g. byte + // slices). + None => quote!(usize), + }, + // If the minimum acceptable value is 1, use the `NonZeroU*` types, with newtype + // wrappers enforcing the maximum acceptable value if relevant. + Some(1) => match integer.maximum { + // If a maximum acceptable value is specified, use the smallest fixed-width + // unsigned type that can fit all acceptable values. + Some(max) => match max { + 0x0000_0000..=0x0000_00fe => { + let max = max as u8; + quote!(crate::types::LimitedNonZeroU8<#max>) + } + 0x0000_00ff => quote!(core::num::NonZeroU8), + 0x0000_0100..=0x0000_fffe => { + let max = max as u16; + quote!(crate::types::LimitedNonZeroU16<#max>) + } + 0x0000_ffff => quote!(core::num::NonZeroU16), + 0x0001_0000..=0xffff_fffe => { + let max = max as u32; + quote!(crate::types::LimitedNonZeroU32<#max>) + } + 0xffff_ffff => quote!(core::num::NonZeroU32), + _ => { + let max = max as u64; + quote!(crate::types::LimitedNonZeroU64<#max>) + } + }, + None => quote!(core::num::NonZeroU64), + }, + // For all other positive minimum acceptable values, use the `NonZeroU*` types + // with newtype wrappers enforcing the minimum and maximum acceptable values. + Some(min) if !min.is_negative() => match integer.maximum { + // If a maximum acceptable value is specified, use the smallest fixed-width + // unsigned type that can fit all acceptable values. + Some(max) => match max { + 0x0000_0000..=0x0000_00ff => { + let min = min as u8; + let max = max as u8; + quote!(crate::types::BoundedU8<#min, #max>) + } + 0x0000_0100..=0x0000_ffff => { + let min = min as u16; + let max = max as u16; + quote!(crate::types::BoundedU16<#min, #max>) + } + 0x0001_0000..=0xffff_ffff => { + let min = min as u32; + let max = max as u32; + quote!(crate::types::BoundedU32<#min, #max>) + } + _ => { + let min = min as u64; + let max = max as u64; + quote!(crate::types::BoundedU64<#min, #max>) + } + }, + None => { + let min = min as u64; + quote!(crate::types::BoundedU64<#min, u64::MAX>) + } + }, + // Use a signed integer type to represent a potentially negative Lexicon integer. + Some(min) => match integer.maximum { + // If a maximum acceptable value is specified, use the smallest fixed-width + // signed type that can fit all acceptable values. + Some(max) => match (min, max) { + (-0x0000_0080, 0x0000_007f) => quote!(i8), + (-0x0000_8000, 0x0000_7fff) => quote!(i16), + (-0x8000_0000, 0x7fff_ffff) => quote!(i32), + (i64::MIN, i64::MAX) => quote!(i64), + // TODO: Implement newtype wrappers for bounded signed integers. + _ => unimplemented!("i64(min: {}, max: {})", min, max), + }, + None => quote!(i64), + }, + None => match integer.maximum { + Some(max) => unimplemented!("i64(max: {})", max), + None => quote!(i64), + }, + }; + Ok((description, typ)) } fn string_type(string: &LexString) -> Result<(TokenStream, TokenStream)> { diff --git a/lexicon/atrium-lex/src/lexicon.rs b/lexicon/atrium-lex/src/lexicon.rs index 32f70ad2..69d6760c 100644 --- a/lexicon/atrium-lex/src/lexicon.rs +++ b/lexicon/atrium-lex/src/lexicon.rs @@ -12,6 +12,12 @@ pub struct LexBoolean { pub r#const: Option, } +/// The Lexicon type `integer`. +/// +/// Lexicon integers are [specified] as signed and 64-bit, which means that values will +/// always fit in an `i64`. +/// +/// [specified]: https://atproto.com/specs/data-model#data-types #[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] pub struct LexInteger {