From 745384ff5812fc695f3e50710b7072c1a683fe18 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Thu, 1 Jun 2023 00:18:50 -0400 Subject: [PATCH] use vec newtype --- .../crates/model/src/entity/access_token.rs | 4 +++- .../crates/model/src/entity/app.rs | 4 +++- .../crates/model/src/entity/emoji.rs | 4 +++- .../crates/model/src/entity/gallery_post.rs | 6 +++-- .../crates/model/src/entity/hashtag.rs | 14 +++++++----- .../model/src/entity/messaging_message.rs | 4 +++- .../crates/model/src/entity/meta.rs | 22 ++++++++++--------- .../crates/model/src/entity/newtype/mod.rs | 6 +++++ .../crates/model/src/entity/note.rs | 14 +++++++----- .../crates/model/src/entity/note_edit.rs | 4 +++- .../crates/model/src/entity/page.rs | 4 +++- .../crates/model/src/entity/poll.rs | 6 +++-- .../crates/model/src/entity/registry_item.rs | 4 +++- .../crates/model/src/entity/reversi_game.rs | 4 +++- .../crates/model/src/entity/user.rs | 6 +++-- .../crates/model/src/entity/user_profile.rs | 4 +++- .../crates/model/src/entity/webhook.rs | 4 +++- 17 files changed, 76 insertions(+), 38 deletions(-) diff --git a/packages/backend/native-utils/crates/model/src/entity/access_token.rs b/packages/backend/native-utils/crates/model/src/entity/access_token.rs index fa9894414..f84971605 100644 --- a/packages/backend/native-utils/crates/model/src/entity/access_token.rs +++ b/packages/backend/native-utils/crates/model/src/entity/access_token.rs @@ -2,6 +2,8 @@ use sea_orm::entity::prelude::*; +use super::newtype::StringVec; + #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "access_token")] pub struct Model { @@ -22,7 +24,7 @@ pub struct Model { pub description: Option, #[sea_orm(column_name = "iconUrl")] pub icon_url: Option, - pub permission: Vec, + pub permission: StringVec, pub fetched: bool, } diff --git a/packages/backend/native-utils/crates/model/src/entity/app.rs b/packages/backend/native-utils/crates/model/src/entity/app.rs index 5f3d5d131..310294568 100644 --- a/packages/backend/native-utils/crates/model/src/entity/app.rs +++ b/packages/backend/native-utils/crates/model/src/entity/app.rs @@ -2,6 +2,8 @@ use sea_orm::entity::prelude::*; +use super::newtype::StringVec; + #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "app")] pub struct Model { @@ -14,7 +16,7 @@ pub struct Model { pub secret: String, pub name: String, pub description: String, - pub permission: Vec, + pub permission: StringVec, #[sea_orm(column_name = "callbackUrl")] pub callback_url: Option, } diff --git a/packages/backend/native-utils/crates/model/src/entity/emoji.rs b/packages/backend/native-utils/crates/model/src/entity/emoji.rs index a89f0b22d..fdb99a2c3 100644 --- a/packages/backend/native-utils/crates/model/src/entity/emoji.rs +++ b/packages/backend/native-utils/crates/model/src/entity/emoji.rs @@ -2,6 +2,8 @@ use sea_orm::entity::prelude::*; +use super::newtype::StringVec; + #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "emoji")] pub struct Model { @@ -15,7 +17,7 @@ pub struct Model { pub original_url: String, pub uri: Option, pub r#type: Option, - pub aliases: Vec, + pub aliases: StringVec, pub category: Option, #[sea_orm(column_name = "publicUrl")] pub public_url: String, diff --git a/packages/backend/native-utils/crates/model/src/entity/gallery_post.rs b/packages/backend/native-utils/crates/model/src/entity/gallery_post.rs index bb68eda62..875d3af58 100644 --- a/packages/backend/native-utils/crates/model/src/entity/gallery_post.rs +++ b/packages/backend/native-utils/crates/model/src/entity/gallery_post.rs @@ -2,6 +2,8 @@ use sea_orm::entity::prelude::*; +use super::newtype::StringVec; + #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "gallery_post")] pub struct Model { @@ -16,12 +18,12 @@ pub struct Model { #[sea_orm(column_name = "userId")] pub user_id: String, #[sea_orm(column_name = "fileIds")] - pub file_ids: Vec, + pub file_ids: StringVec, #[sea_orm(column_name = "isSensitive")] pub is_sensitive: bool, #[sea_orm(column_name = "likedCount")] pub liked_count: i32, - pub tags: Vec, + pub tags: StringVec, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/packages/backend/native-utils/crates/model/src/entity/hashtag.rs b/packages/backend/native-utils/crates/model/src/entity/hashtag.rs index 9a6e44623..917f4ea1b 100644 --- a/packages/backend/native-utils/crates/model/src/entity/hashtag.rs +++ b/packages/backend/native-utils/crates/model/src/entity/hashtag.rs @@ -2,6 +2,8 @@ use sea_orm::entity::prelude::*; +use super::newtype::StringVec; + #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "hashtag")] pub struct Model { @@ -9,27 +11,27 @@ pub struct Model { pub id: String, pub name: String, #[sea_orm(column_name = "mentionedUserIds")] - pub mentioned_user_ids: Vec, + pub mentioned_user_ids: StringVec, #[sea_orm(column_name = "mentionedUsersCount")] pub mentioned_users_count: i32, #[sea_orm(column_name = "mentionedLocalUserIds")] - pub mentioned_local_user_ids: Vec, + pub mentioned_local_user_ids: StringVec, #[sea_orm(column_name = "mentionedLocalUsersCount")] pub mentioned_local_users_count: i32, #[sea_orm(column_name = "mentionedRemoteUserIds")] - pub mentioned_remote_user_ids: Vec, + pub mentioned_remote_user_ids: StringVec, #[sea_orm(column_name = "mentionedRemoteUsersCount")] pub mentioned_remote_users_count: i32, #[sea_orm(column_name = "attachedUserIds")] - pub attached_user_ids: Vec, + pub attached_user_ids: StringVec, #[sea_orm(column_name = "attachedUsersCount")] pub attached_users_count: i32, #[sea_orm(column_name = "attachedLocalUserIds")] - pub attached_local_user_ids: Vec, + pub attached_local_user_ids: StringVec, #[sea_orm(column_name = "attachedLocalUsersCount")] pub attached_local_users_count: i32, #[sea_orm(column_name = "attachedRemoteUserIds")] - pub attached_remote_user_ids: Vec, + pub attached_remote_user_ids: StringVec, #[sea_orm(column_name = "attachedRemoteUsersCount")] pub attached_remote_users_count: i32, } diff --git a/packages/backend/native-utils/crates/model/src/entity/messaging_message.rs b/packages/backend/native-utils/crates/model/src/entity/messaging_message.rs index 0fbfc1ffb..b66c01fc9 100644 --- a/packages/backend/native-utils/crates/model/src/entity/messaging_message.rs +++ b/packages/backend/native-utils/crates/model/src/entity/messaging_message.rs @@ -2,6 +2,8 @@ use sea_orm::entity::prelude::*; +use super::newtype::StringVec; + #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "messaging_message")] pub struct Model { @@ -20,7 +22,7 @@ pub struct Model { pub file_id: Option, #[sea_orm(column_name = "groupId")] pub group_id: Option, - pub reads: Vec, + pub reads: StringVec, pub uri: Option, } diff --git a/packages/backend/native-utils/crates/model/src/entity/meta.rs b/packages/backend/native-utils/crates/model/src/entity/meta.rs index 33ab911ba..a97cb89c4 100644 --- a/packages/backend/native-utils/crates/model/src/entity/meta.rs +++ b/packages/backend/native-utils/crates/model/src/entity/meta.rs @@ -4,6 +4,8 @@ use super::sea_orm_active_enums::MetaSensitivemediadetectionEnum; use super::sea_orm_active_enums::MetaSensitivemediadetectionsensitivityEnum; use sea_orm::entity::prelude::*; +use super::newtype::StringVec; + #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "meta")] pub struct Model { @@ -23,11 +25,11 @@ pub struct Model { pub disable_global_timeline: bool, #[sea_orm(column_name = "useStarForReactionFallback")] pub use_star_for_reaction_fallback: bool, - pub langs: Vec, + pub langs: StringVec, #[sea_orm(column_name = "hiddenTags")] - pub hidden_tags: Vec, + pub hidden_tags: StringVec, #[sea_orm(column_name = "blockedHosts")] - pub blocked_hosts: Vec, + pub blocked_hosts: StringVec, #[sea_orm(column_name = "mascotImageUrl")] pub mascot_image_url: Option, #[sea_orm(column_name = "bannerUrl")] @@ -88,7 +90,7 @@ pub struct Model { #[sea_orm(column_name = "discordClientSecret")] pub discord_client_secret: Option, #[sea_orm(column_name = "pinnedUsers")] - pub pinned_users: Vec, + pub pinned_users: StringVec, #[sea_orm(column_name = "ToSUrl")] pub to_s_url: Option, #[sea_orm(column_name = "repositoryUrl")] @@ -128,7 +130,7 @@ pub struct Model { #[sea_orm(column_name = "objectStorageSetPublicRead")] pub object_storage_set_public_read: bool, #[sea_orm(column_name = "pinnedPages")] - pub pinned_pages: Vec, + pub pinned_pages: StringVec, #[sea_orm(column_name = "backgroundImageUrl")] pub background_image_url: Option, #[sea_orm(column_name = "logoImageUrl")] @@ -138,7 +140,7 @@ pub struct Model { #[sea_orm(column_name = "objectStorageS3ForcePathStyle")] pub object_storage_s3_force_path_style: bool, #[sea_orm(column_name = "allowedHosts")] - pub allowed_hosts: Option>, + pub allowed_hosts: Option, #[sea_orm(column_name = "secureMode")] pub secure_mode: Option, #[sea_orm(column_name = "privateMode")] @@ -168,13 +170,13 @@ pub struct Model { #[sea_orm(column_name = "enableActiveEmailValidation")] pub enable_active_email_validation: bool, #[sea_orm(column_name = "customMOTD")] - pub custom_motd: Vec, + pub custom_motd: StringVec, #[sea_orm(column_name = "customSplashIcons")] - pub custom_splash_icons: Vec, + pub custom_splash_icons: StringVec, #[sea_orm(column_name = "disableRecommendedTimeline")] pub disable_recommended_timeline: bool, #[sea_orm(column_name = "recommendedInstances")] - pub recommended_instances: Vec, + pub recommended_instances: StringVec, #[sea_orm(column_name = "enableGuestTimeline")] pub enable_guest_timeline: bool, #[sea_orm(column_name = "defaultReaction")] @@ -184,7 +186,7 @@ pub struct Model { #[sea_orm(column_name = "libreTranslateApiKey")] pub libre_translate_api_key: Option, #[sea_orm(column_name = "silencedHosts")] - pub silenced_hosts: Vec, + pub silenced_hosts: StringVec, #[sea_orm(column_name = "experimentalFeatures", column_type = "JsonBinary")] pub experimental_features: Json, } diff --git a/packages/backend/native-utils/crates/model/src/entity/newtype/mod.rs b/packages/backend/native-utils/crates/model/src/entity/newtype/mod.rs index 65eba72d7..bd4302441 100644 --- a/packages/backend/native-utils/crates/model/src/entity/newtype/mod.rs +++ b/packages/backend/native-utils/crates/model/src/entity/newtype/mod.rs @@ -15,10 +15,16 @@ impl_json_newtype!(JsonKeyword); pub struct JsonStringVec(pub Vec); impl_json_newtype!(JsonStringVec); +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, From, Into)] +pub struct JsonI32Vec(pub Vec); +impl_json_newtype!(JsonI32Vec); + cfg_if! { if #[cfg(feature = "legacy")] { pub type StringVec = Vec; + pub type I32Vec = Vec; } else { pub type StringVec = JsonStringVec; + pub type I32Vec = JsonI32Vec; } } diff --git a/packages/backend/native-utils/crates/model/src/entity/note.rs b/packages/backend/native-utils/crates/model/src/entity/note.rs index 2e733edae..c2f20c11b 100644 --- a/packages/backend/native-utils/crates/model/src/entity/note.rs +++ b/packages/backend/native-utils/crates/model/src/entity/note.rs @@ -3,6 +3,8 @@ use super::sea_orm_active_enums::NoteVisibilityEnum; use sea_orm::entity::prelude::*; +use super::newtype::StringVec; + #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "note")] pub struct Model { @@ -32,16 +34,16 @@ pub struct Model { pub uri: Option, pub score: i32, #[sea_orm(column_name = "fileIds")] - pub file_ids: Vec, + pub file_ids: StringVec, #[sea_orm(column_name = "attachedFileTypes")] - pub attached_file_types: Vec, + pub attached_file_types: StringVec, #[sea_orm(column_name = "visibleUserIds")] - pub visible_user_ids: Vec, - pub mentions: Vec, + pub visible_user_ids: StringVec, + pub mentions: StringVec, #[sea_orm(column_name = "mentionedRemoteUsers", column_type = "Text")] pub mentioned_remote_users: String, - pub emojis: Vec, - pub tags: Vec, + pub emojis: StringVec, + pub tags: StringVec, #[sea_orm(column_name = "hasPoll")] pub has_poll: bool, #[sea_orm(column_name = "userHost")] diff --git a/packages/backend/native-utils/crates/model/src/entity/note_edit.rs b/packages/backend/native-utils/crates/model/src/entity/note_edit.rs index 5e98b3da4..4e8f42083 100644 --- a/packages/backend/native-utils/crates/model/src/entity/note_edit.rs +++ b/packages/backend/native-utils/crates/model/src/entity/note_edit.rs @@ -2,6 +2,8 @@ use sea_orm::entity::prelude::*; +use super::newtype::StringVec; + #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "note_edit")] pub struct Model { @@ -13,7 +15,7 @@ pub struct Model { pub text: Option, pub cw: Option, #[sea_orm(column_name = "fileIds")] - pub file_ids: Vec, + pub file_ids: StringVec, #[sea_orm(column_name = "updatedAt")] pub updated_at: DateTimeWithTimeZone, } diff --git a/packages/backend/native-utils/crates/model/src/entity/page.rs b/packages/backend/native-utils/crates/model/src/entity/page.rs index efb794944..c3d09fa8c 100644 --- a/packages/backend/native-utils/crates/model/src/entity/page.rs +++ b/packages/backend/native-utils/crates/model/src/entity/page.rs @@ -3,6 +3,8 @@ use super::sea_orm_active_enums::PageVisibilityEnum; use sea_orm::entity::prelude::*; +use super::newtype::StringVec; + #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "page")] pub struct Model { @@ -28,7 +30,7 @@ pub struct Model { pub variables: Json, pub visibility: PageVisibilityEnum, #[sea_orm(column_name = "visibleUserIds")] - pub visible_user_ids: Vec, + pub visible_user_ids: StringVec, #[sea_orm(column_name = "likedCount")] pub liked_count: i32, #[sea_orm(column_name = "hideTitleWhenPinned")] diff --git a/packages/backend/native-utils/crates/model/src/entity/poll.rs b/packages/backend/native-utils/crates/model/src/entity/poll.rs index a4d9e2df1..81953cfba 100644 --- a/packages/backend/native-utils/crates/model/src/entity/poll.rs +++ b/packages/backend/native-utils/crates/model/src/entity/poll.rs @@ -3,6 +3,8 @@ use super::sea_orm_active_enums::PollNotevisibilityEnum; use sea_orm::entity::prelude::*; +use super::newtype::{I32Vec, StringVec}; + #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "poll")] pub struct Model { @@ -11,8 +13,8 @@ pub struct Model { #[sea_orm(column_name = "expiresAt")] pub expires_at: Option, pub multiple: bool, - pub choices: Vec, - pub votes: Vec, + pub choices: StringVec, + pub votes: I32Vec, #[sea_orm(column_name = "noteVisibility")] pub note_visibility: PollNotevisibilityEnum, #[sea_orm(column_name = "userId")] diff --git a/packages/backend/native-utils/crates/model/src/entity/registry_item.rs b/packages/backend/native-utils/crates/model/src/entity/registry_item.rs index 6de0c740f..54d72d5d8 100644 --- a/packages/backend/native-utils/crates/model/src/entity/registry_item.rs +++ b/packages/backend/native-utils/crates/model/src/entity/registry_item.rs @@ -2,6 +2,8 @@ use sea_orm::entity::prelude::*; +use super::newtype::StringVec; + #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "registry_item")] pub struct Model { @@ -14,7 +16,7 @@ pub struct Model { #[sea_orm(column_name = "userId")] pub user_id: String, pub key: String, - pub scope: Vec, + pub scope: StringVec, pub domain: Option, #[sea_orm(column_type = "JsonBinary", nullable)] pub value: Option, diff --git a/packages/backend/native-utils/crates/model/src/entity/reversi_game.rs b/packages/backend/native-utils/crates/model/src/entity/reversi_game.rs index 1e5359280..0c82fccf7 100644 --- a/packages/backend/native-utils/crates/model/src/entity/reversi_game.rs +++ b/packages/backend/native-utils/crates/model/src/entity/reversi_game.rs @@ -2,6 +2,8 @@ use sea_orm::entity::prelude::*; +use super::newtype::StringVec; + #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "reversi_game")] pub struct Model { @@ -29,7 +31,7 @@ pub struct Model { pub surrendered: Option, #[sea_orm(column_type = "JsonBinary")] pub logs: Json, - pub map: Vec, + pub map: StringVec, pub bw: String, #[sea_orm(column_name = "isLlotheo")] pub is_llotheo: bool, diff --git a/packages/backend/native-utils/crates/model/src/entity/user.rs b/packages/backend/native-utils/crates/model/src/entity/user.rs index 79b9fa692..1cf6ac6b7 100644 --- a/packages/backend/native-utils/crates/model/src/entity/user.rs +++ b/packages/backend/native-utils/crates/model/src/entity/user.rs @@ -2,6 +2,8 @@ use sea_orm::entity::prelude::*; +use super::newtype::StringVec; + #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user")] pub struct Model { @@ -27,7 +29,7 @@ pub struct Model { pub avatar_id: Option, #[sea_orm(column_name = "bannerId", unique)] pub banner_id: Option, - pub tags: Vec, + pub tags: StringVec, #[sea_orm(column_name = "isSuspended")] pub is_suspended: bool, #[sea_orm(column_name = "isSilenced")] @@ -42,7 +44,7 @@ pub struct Model { pub is_admin: bool, #[sea_orm(column_name = "isModerator")] pub is_moderator: bool, - pub emojis: Vec, + pub emojis: StringVec, pub host: Option, pub inbox: Option, #[sea_orm(column_name = "sharedInbox")] diff --git a/packages/backend/native-utils/crates/model/src/entity/user_profile.rs b/packages/backend/native-utils/crates/model/src/entity/user_profile.rs index 3a12469d8..d62607f16 100644 --- a/packages/backend/native-utils/crates/model/src/entity/user_profile.rs +++ b/packages/backend/native-utils/crates/model/src/entity/user_profile.rs @@ -3,6 +3,8 @@ use super::sea_orm_active_enums::UserProfileFfvisibilityEnum; use sea_orm::entity::prelude::*; +use super::newtype::StringVec; + #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user_profile")] pub struct Model { @@ -53,7 +55,7 @@ pub struct Model { #[sea_orm(column_name = "mutedWords", column_type = "JsonBinary")] pub muted_words: Json, #[sea_orm(column_name = "mutingNotificationTypes")] - pub muting_notification_types: Vec, + pub muting_notification_types: StringVec, #[sea_orm(column_name = "noCrawle")] pub no_crawle: bool, #[sea_orm(column_name = "receiveAnnouncementEmail")] diff --git a/packages/backend/native-utils/crates/model/src/entity/webhook.rs b/packages/backend/native-utils/crates/model/src/entity/webhook.rs index 952dcbadb..dd3c3c738 100644 --- a/packages/backend/native-utils/crates/model/src/entity/webhook.rs +++ b/packages/backend/native-utils/crates/model/src/entity/webhook.rs @@ -2,6 +2,8 @@ use sea_orm::entity::prelude::*; +use super::newtype::StringVec; + #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "webhook")] pub struct Model { @@ -12,7 +14,7 @@ pub struct Model { #[sea_orm(column_name = "userId")] pub user_id: String, pub name: String, - pub on: Vec, + pub on: StringVec, pub url: String, pub secret: String, pub active: bool,