From 5e9dce3e8c4c87d25b2fb20f51824365e9ad268c Mon Sep 17 00:00:00 2001 From: Namekuji Date: Fri, 2 Jun 2023 09:29:52 -0400 Subject: [PATCH] adjust module structure --- .../backend/native-utils/src/model/schema.rs | 25 ++++---- .../native-utils/src/model/schema/antenna.rs | 60 +++++++++++++++++++ .../native-utils/src/model/schema/napi.rs | 1 - .../src/model/schema/napi/antenna.rs | 57 ------------------ 4 files changed, 72 insertions(+), 71 deletions(-) delete mode 100644 packages/backend/native-utils/src/model/schema/napi.rs delete mode 100644 packages/backend/native-utils/src/model/schema/napi/antenna.rs diff --git a/packages/backend/native-utils/src/model/schema.rs b/packages/backend/native-utils/src/model/schema.rs index 71f9348b32..ef4368dda1 100644 --- a/packages/backend/native-utils/src/model/schema.rs +++ b/packages/backend/native-utils/src/model/schema.rs @@ -5,19 +5,6 @@ use cfg_if::cfg_if; use jsonschema::JSONSchema; use schemars::{schema_for, JsonSchema}; -cfg_if! { - if #[cfg(feature = "napi")] { - mod napi; - pub use self::napi::antenna::Antenna; - pub use self::napi::antenna::AntennaSrc; - } else { - pub use antenna::Antenna; - pub use antenna::AntennaSrc; - pub use app::App; - pub use app::AppPermission; - } -} - /// Structs of schema defitions implement this trait in order to /// provide the JSON Schema validator [`jsonschema::JSONSchema`]. pub trait Schema { @@ -33,3 +20,15 @@ pub trait Schema { .expect("Unable to compile schema") } } + +cfg_if! { + if #[cfg(feature = "napi")] { + pub use antenna::napi::AntennaSchema as Antenna; + pub use antenna::napi::AntennaSrc; + } else { + pub use antenna::Antenna; + pub use antenna::AntennaSrc; + pub use app::App; + pub use app::AppPermission; + } +} diff --git a/packages/backend/native-utils/src/model/schema/antenna.rs b/packages/backend/native-utils/src/model/schema/antenna.rs index 6376b3bc73..8b553c0820 100644 --- a/packages/backend/native-utils/src/model/schema/antenna.rs +++ b/packages/backend/native-utils/src/model/schema/antenna.rs @@ -60,6 +60,66 @@ impl Schema for super::Antenna {} pub static VALIDATOR: Lazy = Lazy::new(|| super::Antenna::validator()); // ---- +#[cfg(feature = "napi")] +pub mod napi { + use napi::bindgen_prelude::*; + use napi_derive::napi; + use parse_display::FromStr; + use schemars::JsonSchema; + use utoipa::ToSchema; + + use crate::model::{entity::antenna, repository::Repository}; + + #[napi] + #[derive(Clone, Debug, PartialEq, Eq, JsonSchema, ToSchema)] + #[serde(rename_all = "camelCase")] + pub struct AntennaSchema { + pub id: String, + pub created_at: String, + pub name: String, + pub keywords: Vec>, + pub exclude_keywords: Vec>, + #[schema(inline)] + pub src: AntennaSrc, + pub user_list_id: Option, + pub user_group_id: Option, + pub users: Vec, + pub instances: Vec, + #[serde(default)] + pub case_sensitive: bool, + #[serde(default)] + pub notify: bool, + #[serde(default)] + pub with_replies: bool, + #[serde(default)] + pub with_file: bool, + #[serde(default)] + pub has_unread_note: bool, + } + + #[napi] + #[derive(Debug, FromStr, PartialEq, Eq, JsonSchema, ToSchema)] + #[serde(rename_all = "camelCase")] + #[display(style = "camelCase")] + #[display("'{}'")] + pub enum AntennaSrc { + Home, + All, + Users, + List, + Group, + Instances, + } + + #[napi] + impl AntennaSchema { + #[napi] + pub async fn pack_by_id(id: String) -> napi::Result { + antenna::Model::pack_by_id(id).await.map_err(Into::into) + } + } +} + #[cfg(test)] mod unit_test { use pretty_assertions::assert_eq; diff --git a/packages/backend/native-utils/src/model/schema/napi.rs b/packages/backend/native-utils/src/model/schema/napi.rs deleted file mode 100644 index 16130e4ccd..0000000000 --- a/packages/backend/native-utils/src/model/schema/napi.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod antenna; diff --git a/packages/backend/native-utils/src/model/schema/napi/antenna.rs b/packages/backend/native-utils/src/model/schema/napi/antenna.rs deleted file mode 100644 index e5c156efad..0000000000 --- a/packages/backend/native-utils/src/model/schema/napi/antenna.rs +++ /dev/null @@ -1,57 +0,0 @@ -use napi::bindgen_prelude::*; -use napi_derive::napi; -use parse_display::FromStr; -use schemars::JsonSchema; -use utoipa::ToSchema; - -use crate::model::entity::antenna::Model; -use crate::model::repository::Repository; - -#[napi] -#[derive(Clone, Debug, PartialEq, Eq, JsonSchema, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct Antenna { - pub id: String, - pub created_at: String, - pub name: String, - pub keywords: Vec>, - pub exclude_keywords: Vec>, - #[schema(inline)] - pub src: AntennaSrc, - pub user_list_id: Option, - pub user_group_id: Option, - pub users: Vec, - pub instances: Vec, - #[serde(default)] - pub case_sensitive: bool, - #[serde(default)] - pub notify: bool, - #[serde(default)] - pub with_replies: bool, - #[serde(default)] - pub with_file: bool, - #[serde(default)] - pub has_unread_note: bool, -} - -#[napi] -#[derive(Debug, FromStr, PartialEq, Eq, JsonSchema, ToSchema)] -#[serde(rename_all = "camelCase")] -#[display(style = "camelCase")] -#[display("'{}'")] -pub enum AntennaSrc { - Home, - All, - Users, - List, - Group, - Instances, -} - -#[napi] -impl Antenna { - #[napi] - pub async fn pack_by_id(id: String) -> napi::Result { - Model::pack_by_id(id).await.map_err(Into::into) - } -}