adjust module structure
This commit is contained in:
parent
148dbbe56d
commit
5e9dce3e8c
|
@ -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<T: JsonSchema> {
|
||||
|
@ -33,3 +20,15 @@ pub trait Schema<T: JsonSchema> {
|
|||
.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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,66 @@ impl Schema<Self> for super::Antenna {}
|
|||
pub static VALIDATOR: Lazy<JSONSchema> = 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<Vec<String>>,
|
||||
pub exclude_keywords: Vec<Vec<String>>,
|
||||
#[schema(inline)]
|
||||
pub src: AntennaSrc,
|
||||
pub user_list_id: Option<String>,
|
||||
pub user_group_id: Option<String>,
|
||||
pub users: Vec<String>,
|
||||
pub instances: Vec<String>,
|
||||
#[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<AntennaSchema> {
|
||||
antenna::Model::pack_by_id(id).await.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod unit_test {
|
||||
use pretty_assertions::assert_eq;
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
pub mod antenna;
|
|
@ -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<Vec<String>>,
|
||||
pub exclude_keywords: Vec<Vec<String>>,
|
||||
#[schema(inline)]
|
||||
pub src: AntennaSrc,
|
||||
pub user_list_id: Option<String>,
|
||||
pub user_group_id: Option<String>,
|
||||
pub users: Vec<String>,
|
||||
pub instances: Vec<String>,
|
||||
#[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<Antenna> {
|
||||
Model::pack_by_id(id).await.map_err(Into::into)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue