Skip to content

Upgrading ts_rs to 10.0.0 #5163

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

Merged
merged 4 commits into from
Nov 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
9 changes: 9 additions & 0 deletions .woodpecker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ steps:
- cargo test --workspace --no-fail-fast
when: *slow_check_paths

check_ts_bindings:
image: *rust_image
environment:
CARGO_HOME: .cargo_home
commands:
- ./scripts/ts_bindings_check.sh
when:
- event: pull_request

check_diesel_migration:
# TODO: use willsquire/diesel-cli image when shared libraries become optional in lemmy_server
image: *rust_image
Expand Down
17 changes: 6 additions & 11 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 @@ -142,10 +142,11 @@ itertools = "0.13.0"
futures = "0.3.30"
http = "1.1"
rosetta-i18n = "0.1.3"
ts-rs = { version = "7.1.1", features = [
ts-rs = { version = "10.0.0", features = [
"serde-compat",
"chrono-impl",
"no-serde-warnings",
"url-impl",
] }
rustls = { version = "0.23.12", features = ["ring"] }
futures-util = "0.3.30"
Expand Down
24 changes: 24 additions & 0 deletions crates/api_common/src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use ts_rs::TS;
pub struct CreateComment {
pub content: String,
pub post_id: PostId,
#[cfg_attr(feature = "full", ts(optional))]
pub parent_id: Option<CommentId>,
#[cfg_attr(feature = "full", ts(optional))]
pub language_id: Option<LanguageId>,
}

Expand All @@ -37,7 +39,9 @@ pub struct GetComment {
/// Edit a comment.
pub struct EditComment {
pub comment_id: CommentId,
#[cfg_attr(feature = "full", ts(optional))]
pub content: Option<String>,
#[cfg_attr(feature = "full", ts(optional))]
pub language_id: Option<LanguageId>,
}

Expand Down Expand Up @@ -69,6 +73,7 @@ pub struct DeleteComment {
pub struct RemoveComment {
pub comment_id: CommentId,
pub removed: bool,
#[cfg_attr(feature = "full", ts(optional))]
pub reason: Option<String>,
}

Expand Down Expand Up @@ -107,17 +112,29 @@ pub struct CreateCommentLike {
#[cfg_attr(feature = "full", ts(export))]
/// Get a list of comments.
pub struct GetComments {
#[cfg_attr(feature = "full", ts(optional))]
pub type_: Option<ListingType>,
#[cfg_attr(feature = "full", ts(optional))]
pub sort: Option<CommentSortType>,
#[cfg_attr(feature = "full", ts(optional))]
pub max_depth: Option<i32>,
#[cfg_attr(feature = "full", ts(optional))]
pub page: Option<i64>,
#[cfg_attr(feature = "full", ts(optional))]
pub limit: Option<i64>,
#[cfg_attr(feature = "full", ts(optional))]
pub community_id: Option<CommunityId>,
#[cfg_attr(feature = "full", ts(optional))]
pub community_name: Option<String>,
#[cfg_attr(feature = "full", ts(optional))]
pub post_id: Option<PostId>,
#[cfg_attr(feature = "full", ts(optional))]
pub parent_id: Option<CommentId>,
#[cfg_attr(feature = "full", ts(optional))]
pub saved_only: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub liked_only: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub disliked_only: Option<bool>,
}

Expand Down Expand Up @@ -161,12 +178,17 @@ pub struct ResolveCommentReport {
#[cfg_attr(feature = "full", ts(export))]
/// List comment reports.
pub struct ListCommentReports {
#[cfg_attr(feature = "full", ts(optional))]
pub comment_id: Option<CommentId>,
#[cfg_attr(feature = "full", ts(optional))]
pub page: Option<i64>,
#[cfg_attr(feature = "full", ts(optional))]
pub limit: Option<i64>,
/// Only shows the unresolved reports
#[cfg_attr(feature = "full", ts(optional))]
pub unresolved_only: Option<bool>,
/// if no community is given, it returns reports for all communities moderated by the auth user
#[cfg_attr(feature = "full", ts(optional))]
pub community_id: Option<CommunityId>,
}

Expand All @@ -185,7 +207,9 @@ pub struct ListCommentReportsResponse {
/// List comment likes. Admins-only.
pub struct ListCommentLikes {
pub comment_id: CommentId,
#[cfg_attr(feature = "full", ts(optional))]
pub page: Option<i64>,
#[cfg_attr(feature = "full", ts(optional))]
pub limit: Option<i64>,
}

Expand Down
32 changes: 32 additions & 0 deletions crates/api_common/src/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ use ts_rs::TS;
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
// TODO make this into a tagged enum
/// Get a community. Must provide either an id, or a name.
pub struct GetCommunity {
#[cfg_attr(feature = "full", ts(optional))]
pub id: Option<CommunityId>,
/// Example: star_trek , or [email protected]
#[cfg_attr(feature = "full", ts(optional))]
pub name: Option<String>,
}

Expand All @@ -33,6 +36,7 @@ pub struct GetCommunity {
/// The community response.
pub struct GetCommunityResponse {
pub community_view: CommunityView,
#[cfg_attr(feature = "full", ts(optional))]
pub site: Option<Site>,
pub moderators: Vec<CommunityModeratorView>,
pub discussion_languages: Vec<LanguageId>,
Expand All @@ -49,18 +53,26 @@ pub struct CreateCommunity {
/// A longer title.
pub title: String,
/// A sidebar for the community in markdown.
#[cfg_attr(feature = "full", ts(optional))]
pub sidebar: Option<String>,
/// A shorter, one line description of your community.
#[cfg_attr(feature = "full", ts(optional))]
pub description: Option<String>,
/// An icon URL.
#[cfg_attr(feature = "full", ts(optional))]
pub icon: Option<String>,
/// A banner URL.
#[cfg_attr(feature = "full", ts(optional))]
pub banner: Option<String>,
/// Whether its an NSFW community.
#[cfg_attr(feature = "full", ts(optional))]
pub nsfw: Option<bool>,
/// Whether to restrict posting only to moderators.
#[cfg_attr(feature = "full", ts(optional))]
pub posting_restricted_to_mods: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub discussion_languages: Option<Vec<LanguageId>>,
#[cfg_attr(feature = "full", ts(optional))]
pub visibility: Option<CommunityVisibility>,
}

Expand All @@ -79,10 +91,15 @@ pub struct CommunityResponse {
#[cfg_attr(feature = "full", ts(export))]
/// Fetches a list of communities.
pub struct ListCommunities {
#[cfg_attr(feature = "full", ts(optional))]
pub type_: Option<ListingType>,
#[cfg_attr(feature = "full", ts(optional))]
pub sort: Option<CommunitySortType>,
#[cfg_attr(feature = "full", ts(optional))]
pub show_nsfw: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub page: Option<i64>,
#[cfg_attr(feature = "full", ts(optional))]
pub limit: Option<i64>,
}

Expand All @@ -105,11 +122,14 @@ pub struct BanFromCommunity {
pub ban: bool,
/// Optionally remove or restore all their data. Useful for new troll accounts.
/// If ban is true, then this means remove. If ban is false, it means restore.
#[cfg_attr(feature = "full", ts(optional))]
pub remove_or_restore_data: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub reason: Option<String>,
/// A time that the ban will expire, in unix epoch seconds.
///
/// An i64 unix timestamp is used for a simpler API client implementation.
#[cfg_attr(feature = "full", ts(optional))]
pub expires: Option<i64>,
}

Expand Down Expand Up @@ -148,20 +168,29 @@ pub struct AddModToCommunityResponse {
pub struct EditCommunity {
pub community_id: CommunityId,
/// A longer title.
#[cfg_attr(feature = "full", ts(optional))]
pub title: Option<String>,
/// A sidebar for the community in markdown.
#[cfg_attr(feature = "full", ts(optional))]
pub sidebar: Option<String>,
/// A shorter, one line description of your community.
#[cfg_attr(feature = "full", ts(optional))]
pub description: Option<String>,
/// An icon URL.
#[cfg_attr(feature = "full", ts(optional))]
pub icon: Option<String>,
/// A banner URL.
#[cfg_attr(feature = "full", ts(optional))]
pub banner: Option<String>,
/// Whether its an NSFW community.
#[cfg_attr(feature = "full", ts(optional))]
pub nsfw: Option<bool>,
/// Whether to restrict posting only to moderators.
#[cfg_attr(feature = "full", ts(optional))]
pub posting_restricted_to_mods: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub discussion_languages: Option<Vec<LanguageId>>,
#[cfg_attr(feature = "full", ts(optional))]
pub visibility: Option<CommunityVisibility>,
}

Expand All @@ -173,6 +202,7 @@ pub struct EditCommunity {
pub struct HideCommunity {
pub community_id: CommunityId,
pub hidden: bool,
#[cfg_attr(feature = "full", ts(optional))]
pub reason: Option<String>,
}

Expand All @@ -194,6 +224,7 @@ pub struct DeleteCommunity {
pub struct RemoveCommunity {
pub community_id: CommunityId,
pub removed: bool,
#[cfg_attr(feature = "full", ts(optional))]
pub reason: Option<String>,
}

Expand Down Expand Up @@ -240,5 +271,6 @@ pub struct TransferCommunity {
#[cfg_attr(feature = "full", ts(export))]
/// Fetches a random community
pub struct GetRandomCommunity {
#[cfg_attr(feature = "full", ts(optional))]
pub type_: Option<ListingType>,
}
4 changes: 4 additions & 0 deletions crates/api_common/src/custom_emoji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ pub struct ListCustomEmojisResponse {
#[cfg_attr(feature = "full", ts(export))]
/// Fetches a list of custom emojis.
pub struct ListCustomEmojis {
#[cfg_attr(feature = "full", ts(optional))]
pub page: Option<i64>,
#[cfg_attr(feature = "full", ts(optional))]
pub limit: Option<i64>,
#[cfg_attr(feature = "full", ts(optional))]
pub category: Option<String>,
#[cfg_attr(feature = "full", ts(optional))]
pub ignore_page_limits: Option<bool>,
}
18 changes: 16 additions & 2 deletions crates/api_common/src/oauth_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ pub struct CreateOAuthProvider {
pub client_id: String,
pub client_secret: String,
pub scopes: String,
#[cfg_attr(feature = "full", ts(optional))]
pub auto_verify_email: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub account_linking_enabled: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub enabled: Option<bool>,
}

Expand All @@ -32,15 +35,25 @@ pub struct CreateOAuthProvider {
/// Edit an external auth method.
pub struct EditOAuthProvider {
pub id: OAuthProviderId,
#[cfg_attr(feature = "full", ts(optional))]
pub display_name: Option<String>,
#[cfg_attr(feature = "full", ts(optional))]
pub authorization_endpoint: Option<String>,
#[cfg_attr(feature = "full", ts(optional))]
pub token_endpoint: Option<String>,
#[cfg_attr(feature = "full", ts(optional))]
pub userinfo_endpoint: Option<String>,
#[cfg_attr(feature = "full", ts(optional))]
pub id_claim: Option<String>,
#[cfg_attr(feature = "full", ts(optional))]
pub client_secret: Option<String>,
#[cfg_attr(feature = "full", ts(optional))]
pub scopes: Option<String>,
#[cfg_attr(feature = "full", ts(optional))]
pub auto_verify_email: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub account_linking_enabled: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub enabled: Option<bool>,
}

Expand All @@ -59,13 +72,14 @@ pub struct DeleteOAuthProvider {
/// Logging in with an OAuth 2.0 authorization
pub struct AuthenticateWithOauth {
pub code: String,
#[cfg_attr(feature = "full", ts(type = "string"))]
pub oauth_provider_id: OAuthProviderId,
#[cfg_attr(feature = "full", ts(type = "string"))]
pub redirect_uri: Url,
#[cfg_attr(feature = "full", ts(optional))]
pub show_nsfw: Option<bool>,
/// Username is mandatory at registration time
#[cfg_attr(feature = "full", ts(optional))]
pub username: Option<String>,
/// An answer is mandatory if require application is enabled on the server
#[cfg_attr(feature = "full", ts(optional))]
pub answer: Option<String>,
}
Loading