From 93b7396990b7f0ad7cefd0d676577fb5aa79f3ba Mon Sep 17 00:00:00 2001 From: naskya Date: Sat, 20 Jan 2024 05:57:00 +0900 Subject: [PATCH] refactor: make database models accesible to napi Co-authored-by: sup39 --- Makefile | 7 ++- neko/index.js | 39 +++++++++++++--- packages/backend/native-utils/Cargo.lock | 3 ++ packages/backend/native-utils/Cargo.toml | 4 +- .../native-utils/src/database/error.rs | 4 +- packages/backend/native-utils/src/lib.rs | 2 +- packages/backend/native-utils/src/macros.rs | 8 ++-- .../src/model/entity/abuse_user_report.rs | 1 + .../src/model/entity/access_token.rs | 1 + .../native-utils/src/model/entity/ad.rs | 1 + .../src/model/entity/announcement.rs | 1 + .../src/model/entity/announcement_read.rs | 1 + .../native-utils/src/model/entity/antenna.rs | 1 + .../native-utils/src/model/entity/app.rs | 1 + .../src/model/entity/attestation_challenge.rs | 1 + .../src/model/entity/auth_session.rs | 1 + .../native-utils/src/model/entity/blocking.rs | 1 + .../native-utils/src/model/entity/channel.rs | 1 + .../src/model/entity/channel_following.rs | 1 + .../src/model/entity/channel_note_pining.rs | 1 + .../native-utils/src/model/entity/clip.rs | 1 + .../src/model/entity/clip_note.rs | 1 + .../src/model/entity/drive_file.rs | 1 + .../src/model/entity/drive_folder.rs | 1 + .../native-utils/src/model/entity/emoji.rs | 1 + .../src/model/entity/follow_request.rs | 1 + .../src/model/entity/following.rs | 1 + .../src/model/entity/gallery_like.rs | 1 + .../src/model/entity/gallery_post.rs | 1 + .../native-utils/src/model/entity/hashtag.rs | 1 + .../native-utils/src/model/entity/instance.rs | 1 + .../src/model/entity/messaging_message.rs | 1 + .../native-utils/src/model/entity/meta.rs | 1 + .../src/model/entity/migrations.rs | 1 + .../src/model/entity/moderation_log.rs | 1 + .../src/model/entity/muted_note.rs | 1 + .../native-utils/src/model/entity/muting.rs | 1 + .../native-utils/src/model/entity/note.rs | 1 + .../src/model/entity/note_edit.rs | 1 + .../src/model/entity/note_favorite.rs | 1 + .../src/model/entity/note_reaction.rs | 1 + .../src/model/entity/note_thread_muting.rs | 1 + .../src/model/entity/note_unread.rs | 1 + .../src/model/entity/note_watching.rs | 1 + .../src/model/entity/notification.rs | 1 + .../native-utils/src/model/entity/page.rs | 1 + .../src/model/entity/page_like.rs | 1 + .../model/entity/password_reset_request.rs | 1 + .../native-utils/src/model/entity/poll.rs | 1 + .../src/model/entity/poll_vote.rs | 1 + .../src/model/entity/promo_note.rs | 1 + .../src/model/entity/promo_read.rs | 1 + .../src/model/entity/registration_ticket.rs | 1 + .../src/model/entity/registry_item.rs | 1 + .../native-utils/src/model/entity/relay.rs | 1 + .../src/model/entity/renote_muting.rs | 1 + .../src/model/entity/reply_muting.rs | 1 + .../src/model/entity/sea_orm_active_enums.rs | 36 ++++++++++----- .../native-utils/src/model/entity/signin.rs | 1 + .../src/model/entity/sw_subscription.rs | 1 + .../src/model/entity/used_username.rs | 1 + .../native-utils/src/model/entity/user.rs | 1 + .../src/model/entity/user_group.rs | 1 + .../src/model/entity/user_group_invitation.rs | 1 + .../src/model/entity/user_group_invite.rs | 1 + .../src/model/entity/user_group_joining.rs | 1 + .../native-utils/src/model/entity/user_ip.rs | 1 + .../src/model/entity/user_keypair.rs | 1 + .../src/model/entity/user_list.rs | 1 + .../src/model/entity/user_list_joining.rs | 1 + .../src/model/entity/user_note_pining.rs | 1 + .../src/model/entity/user_pending.rs | 1 + .../src/model/entity/user_profile.rs | 1 + .../src/model/entity/user_publickey.rs | 1 + .../src/model/entity/user_security_key.rs | 1 + .../native-utils/src/model/entity/webhook.rs | 1 + .../backend/native-utils/src/model/error.rs | 4 +- .../backend/native-utils/src/util/acct.rs | 6 +-- .../native-utils/src/util/convert_host.rs | 10 ++-- .../src/util/convert_to_hidden_post.rs | 4 +- .../native-utils/src/util/escape_sql.rs | 4 +- .../src/util/format_milliseconds.rs | 2 +- packages/backend/native-utils/src/util/id.rs | 46 +++++++++---------- .../backend/native-utils/src/util/random.rs | 2 +- 84 files changed, 181 insertions(+), 68 deletions(-) diff --git a/Makefile b/Makefile index 7d6b1f8a5..4b08955c4 100644 --- a/Makefile +++ b/Makefile @@ -31,8 +31,11 @@ regenerate-entities: cd packages/backend/native-utils && \ sea-orm-cli generate entity \ --output-dir='src/model/entity' \ - --database-url='postgres://firefish:password@localhost:25432/firefish_db' - + --database-url='postgres://firefish:password@localhost:25432/firefish_db' \ + --date-time-crate='chrono' \ + --model-extra-attributes='napi_derive::napi(object)' + sed -i 's/#\[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)\]/#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]\n#[napi_derive::napi]/' \ + packages/backend/native-utils/src/model/entity/sea_orm_active_enums.rs .PHONY: update-index-js update-index-js: diff --git a/neko/index.js b/neko/index.js index ebfc5d97f..56e517632 100644 --- a/neko/index.js +++ b/neko/index.js @@ -269,6 +269,18 @@ const { EnvConfig, readEnvironmentConfig, readServerConfig, + AntennaSrcEnum, + MetaSensitivemediadetectionEnum, + MetaSensitivemediadetectionsensitivityEnum, + MutedNoteReasonEnum, + NoteVisibilityEnum, + NotificationTypeEnum, + PageVisibilityEnum, + PollNotevisibilityEnum, + RelayStatusEnum, + UserEmojimodpermEnum, + UserProfileFfvisibilityEnum, + UserProfileMutingnotificationtypesEnum, stringToAcct, acctToString, getFullApAccount, @@ -280,17 +292,32 @@ const { sqlLikeEscape, safeForSql, formatMilliseconds, + nativeInitIdGenerator, + nativeCreateId, + nativeGetTimestamp, genString, IdConvertType, convertId, - nativeGetTimestamp, - nativeCreateId, - nativeInitIdGenerator, } = nativeBinding; module.exports.EnvConfig = EnvConfig; module.exports.readEnvironmentConfig = readEnvironmentConfig; module.exports.readServerConfig = readServerConfig; +module.exports.AntennaSrcEnum = AntennaSrcEnum; +module.exports.MetaSensitivemediadetectionEnum = + MetaSensitivemediadetectionEnum; +module.exports.MetaSensitivemediadetectionsensitivityEnum = + MetaSensitivemediadetectionsensitivityEnum; +module.exports.MutedNoteReasonEnum = MutedNoteReasonEnum; +module.exports.NoteVisibilityEnum = NoteVisibilityEnum; +module.exports.NotificationTypeEnum = NotificationTypeEnum; +module.exports.PageVisibilityEnum = PageVisibilityEnum; +module.exports.PollNotevisibilityEnum = PollNotevisibilityEnum; +module.exports.RelayStatusEnum = RelayStatusEnum; +module.exports.UserEmojimodpermEnum = UserEmojimodpermEnum; +module.exports.UserProfileFfvisibilityEnum = UserProfileFfvisibilityEnum; +module.exports.UserProfileMutingnotificationtypesEnum = + UserProfileMutingnotificationtypesEnum; module.exports.stringToAcct = stringToAcct; module.exports.acctToString = acctToString; module.exports.getFullApAccount = getFullApAccount; @@ -302,9 +329,9 @@ module.exports.convertToHiddenPost = convertToHiddenPost; module.exports.sqlLikeEscape = sqlLikeEscape; module.exports.safeForSql = safeForSql; module.exports.formatMilliseconds = formatMilliseconds; +module.exports.nativeInitIdGenerator = nativeInitIdGenerator; +module.exports.nativeCreateId = nativeCreateId; +module.exports.nativeGetTimestamp = nativeGetTimestamp; module.exports.genString = genString; module.exports.IdConvertType = IdConvertType; module.exports.convertId = convertId; -module.exports.nativeGetTimestamp = nativeGetTimestamp; -module.exports.nativeCreateId = nativeCreateId; -module.exports.nativeInitIdGenerator = nativeInitIdGenerator; diff --git a/packages/backend/native-utils/Cargo.lock b/packages/backend/native-utils/Cargo.lock index ad483e917..eb41326c0 100644 --- a/packages/backend/native-utils/Cargo.lock +++ b/packages/backend/native-utils/Cargo.lock @@ -1351,10 +1351,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fc1cb00cde484640da9f01a124edbb013576a6ae9843b23857c940936b76d91" dependencies = [ "bitflags 2.4.2", + "chrono", "ctor", "napi-derive", "napi-sys", "once_cell", + "serde", + "serde_json", "tokio", ] diff --git a/packages/backend/native-utils/Cargo.toml b/packages/backend/native-utils/Cargo.toml index 0c7d3ac1c..161d18200 100644 --- a/packages/backend/native-utils/Cargo.toml +++ b/packages/backend/native-utils/Cargo.toml @@ -7,7 +7,7 @@ version = "0.0.0" members = ["migration"] [features] -default = [] +default = ["napi"] napi = ["dep:napi-derive"] [lib] @@ -33,7 +33,7 @@ tokio = { version = "1.35.1", features = ["full"] } url = "2.5.0" # Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix -napi = { version = "2.14.2", default-features = false, features = ["napi9", "tokio_rt"] } +napi = { version = "2.14.2", default-features = false, features = ["napi9", "tokio_rt", "chrono_date", "serde-json"] } napi-derive = { version = "2.14.6", optional = true } basen = "0.1.0" diff --git a/packages/backend/native-utils/src/database/error.rs b/packages/backend/native-utils/src/database/error.rs index 68e959e0a..f180870fa 100644 --- a/packages/backend/native-utils/src/database/error.rs +++ b/packages/backend/native-utils/src/database/error.rs @@ -1,6 +1,6 @@ use sea_orm::error::DbErr; -use crate::impl_into_napi_error; +use crate::impl_napi_error_from; #[derive(thiserror::Error, Debug, PartialEq, Eq)] pub enum Error { @@ -10,4 +10,4 @@ pub enum Error { OrmError(#[from] DbErr), } -impl_into_napi_error!(Error); +impl_napi_error_from!(Error); diff --git a/packages/backend/native-utils/src/lib.rs b/packages/backend/native-utils/src/lib.rs index 9e0bd3ece..2c57743eb 100644 --- a/packages/backend/native-utils/src/lib.rs +++ b/packages/backend/native-utils/src/lib.rs @@ -4,5 +4,5 @@ pub mod macros; pub mod model; pub mod util; -#[cfg(feature = "napi")] +// #[cfg(feature = "napi")] pub mod mastodon_api; diff --git a/packages/backend/native-utils/src/macros.rs b/packages/backend/native-utils/src/macros.rs index 49ab82632..b2549227f 100644 --- a/packages/backend/native-utils/src/macros.rs +++ b/packages/backend/native-utils/src/macros.rs @@ -1,10 +1,10 @@ #[macro_export] -macro_rules! impl_into_napi_error { +macro_rules! impl_napi_error_from { ($a:ty) => { #[cfg(feature = "napi")] - impl Into for $a { - fn into(self) -> napi::Error { - napi::Error::from_reason(self.to_string()) + impl From<$a> for napi::Error { + fn from(reason: $a) -> napi::Error { + napi::Error::from_reason(reason.to_string()) } } }; diff --git a/packages/backend/native-utils/src/model/entity/abuse_user_report.rs b/packages/backend/native-utils/src/model/entity/abuse_user_report.rs index 72ec038f9..cdea8b461 100644 --- a/packages/backend/native-utils/src/model/entity/abuse_user_report.rs +++ b/packages/backend/native-utils/src/model/entity/abuse_user_report.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "abuse_user_report")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/access_token.rs b/packages/backend/native-utils/src/model/entity/access_token.rs index 8609d569d..65bcb2117 100644 --- a/packages/backend/native-utils/src/model/entity/access_token.rs +++ b/packages/backend/native-utils/src/model/entity/access_token.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "access_token")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/ad.rs b/packages/backend/native-utils/src/model/entity/ad.rs index 747696851..cd06ebf0f 100644 --- a/packages/backend/native-utils/src/model/entity/ad.rs +++ b/packages/backend/native-utils/src/model/entity/ad.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "ad")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/announcement.rs b/packages/backend/native-utils/src/model/entity/announcement.rs index 07c0f3341..2fe428350 100644 --- a/packages/backend/native-utils/src/model/entity/announcement.rs +++ b/packages/backend/native-utils/src/model/entity/announcement.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "announcement")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/announcement_read.rs b/packages/backend/native-utils/src/model/entity/announcement_read.rs index 823175259..bb524a0fb 100644 --- a/packages/backend/native-utils/src/model/entity/announcement_read.rs +++ b/packages/backend/native-utils/src/model/entity/announcement_read.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "announcement_read")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/antenna.rs b/packages/backend/native-utils/src/model/entity/antenna.rs index 66474b725..1a8d923ff 100644 --- a/packages/backend/native-utils/src/model/entity/antenna.rs +++ b/packages/backend/native-utils/src/model/entity/antenna.rs @@ -5,6 +5,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "antenna")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/app.rs b/packages/backend/native-utils/src/model/entity/app.rs index d7c7eedbd..3d05eab29 100644 --- a/packages/backend/native-utils/src/model/entity/app.rs +++ b/packages/backend/native-utils/src/model/entity/app.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "app")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/attestation_challenge.rs b/packages/backend/native-utils/src/model/entity/attestation_challenge.rs index ca9b8cf3c..d5242dff2 100644 --- a/packages/backend/native-utils/src/model/entity/attestation_challenge.rs +++ b/packages/backend/native-utils/src/model/entity/attestation_challenge.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "attestation_challenge")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/auth_session.rs b/packages/backend/native-utils/src/model/entity/auth_session.rs index 63df331d3..9ff792eca 100644 --- a/packages/backend/native-utils/src/model/entity/auth_session.rs +++ b/packages/backend/native-utils/src/model/entity/auth_session.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "auth_session")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/blocking.rs b/packages/backend/native-utils/src/model/entity/blocking.rs index 2a8ad3668..f10039e77 100644 --- a/packages/backend/native-utils/src/model/entity/blocking.rs +++ b/packages/backend/native-utils/src/model/entity/blocking.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "blocking")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/channel.rs b/packages/backend/native-utils/src/model/entity/channel.rs index 64415405e..785f0a4d4 100644 --- a/packages/backend/native-utils/src/model/entity/channel.rs +++ b/packages/backend/native-utils/src/model/entity/channel.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "channel")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/channel_following.rs b/packages/backend/native-utils/src/model/entity/channel_following.rs index 67a0492e7..ac1c8d139 100644 --- a/packages/backend/native-utils/src/model/entity/channel_following.rs +++ b/packages/backend/native-utils/src/model/entity/channel_following.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "channel_following")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/channel_note_pining.rs b/packages/backend/native-utils/src/model/entity/channel_note_pining.rs index bcd3f72ef..f885400a9 100644 --- a/packages/backend/native-utils/src/model/entity/channel_note_pining.rs +++ b/packages/backend/native-utils/src/model/entity/channel_note_pining.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "channel_note_pining")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/clip.rs b/packages/backend/native-utils/src/model/entity/clip.rs index 7838df9e3..0f2858796 100644 --- a/packages/backend/native-utils/src/model/entity/clip.rs +++ b/packages/backend/native-utils/src/model/entity/clip.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "clip")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/clip_note.rs b/packages/backend/native-utils/src/model/entity/clip_note.rs index 28f599a38..29c174f5c 100644 --- a/packages/backend/native-utils/src/model/entity/clip_note.rs +++ b/packages/backend/native-utils/src/model/entity/clip_note.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "clip_note")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/drive_file.rs b/packages/backend/native-utils/src/model/entity/drive_file.rs index 406e3e1de..5ce766dc0 100644 --- a/packages/backend/native-utils/src/model/entity/drive_file.rs +++ b/packages/backend/native-utils/src/model/entity/drive_file.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "drive_file")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/drive_folder.rs b/packages/backend/native-utils/src/model/entity/drive_folder.rs index 3906b4015..48d39f2f4 100644 --- a/packages/backend/native-utils/src/model/entity/drive_folder.rs +++ b/packages/backend/native-utils/src/model/entity/drive_folder.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "drive_folder")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/emoji.rs b/packages/backend/native-utils/src/model/entity/emoji.rs index fc479a2d7..87835b305 100644 --- a/packages/backend/native-utils/src/model/entity/emoji.rs +++ b/packages/backend/native-utils/src/model/entity/emoji.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "emoji")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/follow_request.rs b/packages/backend/native-utils/src/model/entity/follow_request.rs index be2e38649..892327edc 100644 --- a/packages/backend/native-utils/src/model/entity/follow_request.rs +++ b/packages/backend/native-utils/src/model/entity/follow_request.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "follow_request")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/following.rs b/packages/backend/native-utils/src/model/entity/following.rs index c6313cd28..015896e80 100644 --- a/packages/backend/native-utils/src/model/entity/following.rs +++ b/packages/backend/native-utils/src/model/entity/following.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "following")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/gallery_like.rs b/packages/backend/native-utils/src/model/entity/gallery_like.rs index 0a41c09ee..58673dc30 100644 --- a/packages/backend/native-utils/src/model/entity/gallery_like.rs +++ b/packages/backend/native-utils/src/model/entity/gallery_like.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "gallery_like")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/gallery_post.rs b/packages/backend/native-utils/src/model/entity/gallery_post.rs index 2a8689295..98ff7a437 100644 --- a/packages/backend/native-utils/src/model/entity/gallery_post.rs +++ b/packages/backend/native-utils/src/model/entity/gallery_post.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "gallery_post")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/hashtag.rs b/packages/backend/native-utils/src/model/entity/hashtag.rs index 568e6a15b..71aa49f63 100644 --- a/packages/backend/native-utils/src/model/entity/hashtag.rs +++ b/packages/backend/native-utils/src/model/entity/hashtag.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "hashtag")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/instance.rs b/packages/backend/native-utils/src/model/entity/instance.rs index b95ffbece..1f550436c 100644 --- a/packages/backend/native-utils/src/model/entity/instance.rs +++ b/packages/backend/native-utils/src/model/entity/instance.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "instance")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/messaging_message.rs b/packages/backend/native-utils/src/model/entity/messaging_message.rs index 3e9bb8647..02be149cf 100644 --- a/packages/backend/native-utils/src/model/entity/messaging_message.rs +++ b/packages/backend/native-utils/src/model/entity/messaging_message.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "messaging_message")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/meta.rs b/packages/backend/native-utils/src/model/entity/meta.rs index 51b689c9a..27a33fddf 100644 --- a/packages/backend/native-utils/src/model/entity/meta.rs +++ b/packages/backend/native-utils/src/model/entity/meta.rs @@ -6,6 +6,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "meta")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/migrations.rs b/packages/backend/native-utils/src/model/entity/migrations.rs index 4d67361c1..2c591d70e 100644 --- a/packages/backend/native-utils/src/model/entity/migrations.rs +++ b/packages/backend/native-utils/src/model/entity/migrations.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "migrations")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key)] pub id: i32, diff --git a/packages/backend/native-utils/src/model/entity/moderation_log.rs b/packages/backend/native-utils/src/model/entity/moderation_log.rs index 9e7003f0d..fc642350d 100644 --- a/packages/backend/native-utils/src/model/entity/moderation_log.rs +++ b/packages/backend/native-utils/src/model/entity/moderation_log.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "moderation_log")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/muted_note.rs b/packages/backend/native-utils/src/model/entity/muted_note.rs index 037f8fa8a..99b648bdd 100644 --- a/packages/backend/native-utils/src/model/entity/muted_note.rs +++ b/packages/backend/native-utils/src/model/entity/muted_note.rs @@ -5,6 +5,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "muted_note")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/muting.rs b/packages/backend/native-utils/src/model/entity/muting.rs index e852391dc..62617bf1c 100644 --- a/packages/backend/native-utils/src/model/entity/muting.rs +++ b/packages/backend/native-utils/src/model/entity/muting.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "muting")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/note.rs b/packages/backend/native-utils/src/model/entity/note.rs index c5491915c..b92926859 100644 --- a/packages/backend/native-utils/src/model/entity/note.rs +++ b/packages/backend/native-utils/src/model/entity/note.rs @@ -5,6 +5,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "note")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/note_edit.rs b/packages/backend/native-utils/src/model/entity/note_edit.rs index 6b5e3f04c..b619c069a 100644 --- a/packages/backend/native-utils/src/model/entity/note_edit.rs +++ b/packages/backend/native-utils/src/model/entity/note_edit.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "note_edit")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/note_favorite.rs b/packages/backend/native-utils/src/model/entity/note_favorite.rs index e1b2c31dd..f1e78cac1 100644 --- a/packages/backend/native-utils/src/model/entity/note_favorite.rs +++ b/packages/backend/native-utils/src/model/entity/note_favorite.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "note_favorite")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/note_reaction.rs b/packages/backend/native-utils/src/model/entity/note_reaction.rs index ad6b385db..dd1bc2661 100644 --- a/packages/backend/native-utils/src/model/entity/note_reaction.rs +++ b/packages/backend/native-utils/src/model/entity/note_reaction.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "note_reaction")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/note_thread_muting.rs b/packages/backend/native-utils/src/model/entity/note_thread_muting.rs index 84fd0f311..07883afaf 100644 --- a/packages/backend/native-utils/src/model/entity/note_thread_muting.rs +++ b/packages/backend/native-utils/src/model/entity/note_thread_muting.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "note_thread_muting")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/note_unread.rs b/packages/backend/native-utils/src/model/entity/note_unread.rs index 6f6cb3d61..62a8dbde0 100644 --- a/packages/backend/native-utils/src/model/entity/note_unread.rs +++ b/packages/backend/native-utils/src/model/entity/note_unread.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "note_unread")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/note_watching.rs b/packages/backend/native-utils/src/model/entity/note_watching.rs index 8febf3630..aee1c0eaf 100644 --- a/packages/backend/native-utils/src/model/entity/note_watching.rs +++ b/packages/backend/native-utils/src/model/entity/note_watching.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "note_watching")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/notification.rs b/packages/backend/native-utils/src/model/entity/notification.rs index 72f01f295..5da963a4f 100644 --- a/packages/backend/native-utils/src/model/entity/notification.rs +++ b/packages/backend/native-utils/src/model/entity/notification.rs @@ -5,6 +5,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "notification")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/page.rs b/packages/backend/native-utils/src/model/entity/page.rs index fe59a50b7..ea5c4c138 100644 --- a/packages/backend/native-utils/src/model/entity/page.rs +++ b/packages/backend/native-utils/src/model/entity/page.rs @@ -5,6 +5,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "page")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/page_like.rs b/packages/backend/native-utils/src/model/entity/page_like.rs index c608dcf48..dec0f5bf1 100644 --- a/packages/backend/native-utils/src/model/entity/page_like.rs +++ b/packages/backend/native-utils/src/model/entity/page_like.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "page_like")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/password_reset_request.rs b/packages/backend/native-utils/src/model/entity/password_reset_request.rs index a4610b177..ac95ce672 100644 --- a/packages/backend/native-utils/src/model/entity/password_reset_request.rs +++ b/packages/backend/native-utils/src/model/entity/password_reset_request.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "password_reset_request")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/poll.rs b/packages/backend/native-utils/src/model/entity/poll.rs index 9418ad6a5..eed954736 100644 --- a/packages/backend/native-utils/src/model/entity/poll.rs +++ b/packages/backend/native-utils/src/model/entity/poll.rs @@ -5,6 +5,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "poll")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(column_name = "noteId", primary_key, auto_increment = false, unique)] pub note_id: String, diff --git a/packages/backend/native-utils/src/model/entity/poll_vote.rs b/packages/backend/native-utils/src/model/entity/poll_vote.rs index 0990dab9b..68040fcfe 100644 --- a/packages/backend/native-utils/src/model/entity/poll_vote.rs +++ b/packages/backend/native-utils/src/model/entity/poll_vote.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "poll_vote")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/promo_note.rs b/packages/backend/native-utils/src/model/entity/promo_note.rs index 1ee07df32..6fd235e1b 100644 --- a/packages/backend/native-utils/src/model/entity/promo_note.rs +++ b/packages/backend/native-utils/src/model/entity/promo_note.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "promo_note")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(column_name = "noteId", primary_key, auto_increment = false, unique)] pub note_id: String, diff --git a/packages/backend/native-utils/src/model/entity/promo_read.rs b/packages/backend/native-utils/src/model/entity/promo_read.rs index a0015f878..5a8028959 100644 --- a/packages/backend/native-utils/src/model/entity/promo_read.rs +++ b/packages/backend/native-utils/src/model/entity/promo_read.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "promo_read")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/registration_ticket.rs b/packages/backend/native-utils/src/model/entity/registration_ticket.rs index 577a9b36c..c4bf3c68d 100644 --- a/packages/backend/native-utils/src/model/entity/registration_ticket.rs +++ b/packages/backend/native-utils/src/model/entity/registration_ticket.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "registration_ticket")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/registry_item.rs b/packages/backend/native-utils/src/model/entity/registry_item.rs index a3bfdb8b1..c35fba391 100644 --- a/packages/backend/native-utils/src/model/entity/registry_item.rs +++ b/packages/backend/native-utils/src/model/entity/registry_item.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "registry_item")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/relay.rs b/packages/backend/native-utils/src/model/entity/relay.rs index dbd2d3251..884cf570f 100644 --- a/packages/backend/native-utils/src/model/entity/relay.rs +++ b/packages/backend/native-utils/src/model/entity/relay.rs @@ -5,6 +5,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "relay")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/renote_muting.rs b/packages/backend/native-utils/src/model/entity/renote_muting.rs index cf3312e68..fab315b84 100644 --- a/packages/backend/native-utils/src/model/entity/renote_muting.rs +++ b/packages/backend/native-utils/src/model/entity/renote_muting.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "renote_muting")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/reply_muting.rs b/packages/backend/native-utils/src/model/entity/reply_muting.rs index 67c0289ea..a34d8a61f 100644 --- a/packages/backend/native-utils/src/model/entity/reply_muting.rs +++ b/packages/backend/native-utils/src/model/entity/reply_muting.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "reply_muting")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/sea_orm_active_enums.rs b/packages/backend/native-utils/src/model/entity/sea_orm_active_enums.rs index ec1a80d9d..7439f0f51 100644 --- a/packages/backend/native-utils/src/model/entity/sea_orm_active_enums.rs +++ b/packages/backend/native-utils/src/model/entity/sea_orm_active_enums.rs @@ -2,7 +2,8 @@ use sea_orm::entity::prelude::*; -#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[napi_derive::napi] #[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "antenna_src_enum")] pub enum AntennaSrcEnum { #[sea_orm(string_value = "all")] @@ -18,7 +19,8 @@ pub enum AntennaSrcEnum { #[sea_orm(string_value = "users")] Users, } -#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[napi_derive::napi] #[sea_orm( rs_type = "String", db_type = "Enum", @@ -34,7 +36,8 @@ pub enum MetaSensitivemediadetectionEnum { #[sea_orm(string_value = "remote")] Remote, } -#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[napi_derive::napi] #[sea_orm( rs_type = "String", db_type = "Enum", @@ -52,7 +55,8 @@ pub enum MetaSensitivemediadetectionsensitivityEnum { #[sea_orm(string_value = "veryLow")] VeryLow, } -#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[napi_derive::napi] #[sea_orm( rs_type = "String", db_type = "Enum", @@ -68,7 +72,8 @@ pub enum MutedNoteReasonEnum { #[sea_orm(string_value = "word")] Word, } -#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[napi_derive::napi] #[sea_orm( rs_type = "String", db_type = "Enum", @@ -86,7 +91,8 @@ pub enum NoteVisibilityEnum { #[sea_orm(string_value = "specified")] Specified, } -#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[napi_derive::napi] #[sea_orm( rs_type = "String", db_type = "Enum", @@ -118,7 +124,8 @@ pub enum NotificationTypeEnum { #[sea_orm(string_value = "reply")] Reply, } -#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[napi_derive::napi] #[sea_orm( rs_type = "String", db_type = "Enum", @@ -132,7 +139,8 @@ pub enum PageVisibilityEnum { #[sea_orm(string_value = "specified")] Specified, } -#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[napi_derive::napi] #[sea_orm( rs_type = "String", db_type = "Enum", @@ -148,7 +156,8 @@ pub enum PollNotevisibilityEnum { #[sea_orm(string_value = "specified")] Specified, } -#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[napi_derive::napi] #[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "relay_status_enum")] pub enum RelayStatusEnum { #[sea_orm(string_value = "accepted")] @@ -158,7 +167,8 @@ pub enum RelayStatusEnum { #[sea_orm(string_value = "requesting")] Requesting, } -#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[napi_derive::napi] #[sea_orm( rs_type = "String", db_type = "Enum", @@ -174,7 +184,8 @@ pub enum UserEmojimodpermEnum { #[sea_orm(string_value = "unauthorized")] Unauthorized, } -#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[napi_derive::napi] #[sea_orm( rs_type = "String", db_type = "Enum", @@ -188,7 +199,8 @@ pub enum UserProfileFfvisibilityEnum { #[sea_orm(string_value = "public")] Public, } -#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] +#[napi_derive::napi] #[sea_orm( rs_type = "String", db_type = "Enum", diff --git a/packages/backend/native-utils/src/model/entity/signin.rs b/packages/backend/native-utils/src/model/entity/signin.rs index 74be51c73..85396b5aa 100644 --- a/packages/backend/native-utils/src/model/entity/signin.rs +++ b/packages/backend/native-utils/src/model/entity/signin.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "signin")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/sw_subscription.rs b/packages/backend/native-utils/src/model/entity/sw_subscription.rs index 480836e93..8899e6ed2 100644 --- a/packages/backend/native-utils/src/model/entity/sw_subscription.rs +++ b/packages/backend/native-utils/src/model/entity/sw_subscription.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "sw_subscription")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/used_username.rs b/packages/backend/native-utils/src/model/entity/used_username.rs index 8509793ae..f3ffb0f67 100644 --- a/packages/backend/native-utils/src/model/entity/used_username.rs +++ b/packages/backend/native-utils/src/model/entity/used_username.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "used_username")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub username: String, diff --git a/packages/backend/native-utils/src/model/entity/user.rs b/packages/backend/native-utils/src/model/entity/user.rs index 8ace9fc60..82a8e676a 100644 --- a/packages/backend/native-utils/src/model/entity/user.rs +++ b/packages/backend/native-utils/src/model/entity/user.rs @@ -5,6 +5,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/user_group.rs b/packages/backend/native-utils/src/model/entity/user_group.rs index 75d0a6eeb..6d7958864 100644 --- a/packages/backend/native-utils/src/model/entity/user_group.rs +++ b/packages/backend/native-utils/src/model/entity/user_group.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user_group")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/user_group_invitation.rs b/packages/backend/native-utils/src/model/entity/user_group_invitation.rs index 2fd78d51d..ee7edd8b8 100644 --- a/packages/backend/native-utils/src/model/entity/user_group_invitation.rs +++ b/packages/backend/native-utils/src/model/entity/user_group_invitation.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user_group_invitation")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/user_group_invite.rs b/packages/backend/native-utils/src/model/entity/user_group_invite.rs index a7d73b179..f49e40f11 100644 --- a/packages/backend/native-utils/src/model/entity/user_group_invite.rs +++ b/packages/backend/native-utils/src/model/entity/user_group_invite.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user_group_invite")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/user_group_joining.rs b/packages/backend/native-utils/src/model/entity/user_group_joining.rs index 6f43fc9d5..d34a3a6c3 100644 --- a/packages/backend/native-utils/src/model/entity/user_group_joining.rs +++ b/packages/backend/native-utils/src/model/entity/user_group_joining.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user_group_joining")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/user_ip.rs b/packages/backend/native-utils/src/model/entity/user_ip.rs index e4abec555..36ab2f9b0 100644 --- a/packages/backend/native-utils/src/model/entity/user_ip.rs +++ b/packages/backend/native-utils/src/model/entity/user_ip.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user_ip")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key)] pub id: i32, diff --git a/packages/backend/native-utils/src/model/entity/user_keypair.rs b/packages/backend/native-utils/src/model/entity/user_keypair.rs index 22a5054b9..454f959a2 100644 --- a/packages/backend/native-utils/src/model/entity/user_keypair.rs +++ b/packages/backend/native-utils/src/model/entity/user_keypair.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user_keypair")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(column_name = "userId", primary_key, auto_increment = false, unique)] pub user_id: String, diff --git a/packages/backend/native-utils/src/model/entity/user_list.rs b/packages/backend/native-utils/src/model/entity/user_list.rs index 01411cb59..0e900ee88 100644 --- a/packages/backend/native-utils/src/model/entity/user_list.rs +++ b/packages/backend/native-utils/src/model/entity/user_list.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user_list")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/user_list_joining.rs b/packages/backend/native-utils/src/model/entity/user_list_joining.rs index 63296dd6d..c77ec392b 100644 --- a/packages/backend/native-utils/src/model/entity/user_list_joining.rs +++ b/packages/backend/native-utils/src/model/entity/user_list_joining.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user_list_joining")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/user_note_pining.rs b/packages/backend/native-utils/src/model/entity/user_note_pining.rs index b043b5934..c29b54709 100644 --- a/packages/backend/native-utils/src/model/entity/user_note_pining.rs +++ b/packages/backend/native-utils/src/model/entity/user_note_pining.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user_note_pining")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/user_pending.rs b/packages/backend/native-utils/src/model/entity/user_pending.rs index 863783b76..8a2f1806b 100644 --- a/packages/backend/native-utils/src/model/entity/user_pending.rs +++ b/packages/backend/native-utils/src/model/entity/user_pending.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user_pending")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/user_profile.rs b/packages/backend/native-utils/src/model/entity/user_profile.rs index 2b37ba02e..7ff52bea6 100644 --- a/packages/backend/native-utils/src/model/entity/user_profile.rs +++ b/packages/backend/native-utils/src/model/entity/user_profile.rs @@ -6,6 +6,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user_profile")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(column_name = "userId", primary_key, auto_increment = false, unique)] pub user_id: String, diff --git a/packages/backend/native-utils/src/model/entity/user_publickey.rs b/packages/backend/native-utils/src/model/entity/user_publickey.rs index 97c433ff5..994cfd336 100644 --- a/packages/backend/native-utils/src/model/entity/user_publickey.rs +++ b/packages/backend/native-utils/src/model/entity/user_publickey.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user_publickey")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(column_name = "userId", primary_key, auto_increment = false, unique)] pub user_id: String, diff --git a/packages/backend/native-utils/src/model/entity/user_security_key.rs b/packages/backend/native-utils/src/model/entity/user_security_key.rs index 28620229c..67d43843b 100644 --- a/packages/backend/native-utils/src/model/entity/user_security_key.rs +++ b/packages/backend/native-utils/src/model/entity/user_security_key.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user_security_key")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/entity/webhook.rs b/packages/backend/native-utils/src/model/entity/webhook.rs index 06d41b9d9..e4e2b14f9 100644 --- a/packages/backend/native-utils/src/model/entity/webhook.rs +++ b/packages/backend/native-utils/src/model/entity/webhook.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "webhook")] +#[napi_derive::napi(object)] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/packages/backend/native-utils/src/model/error.rs b/packages/backend/native-utils/src/model/error.rs index 8e9213066..a97172636 100644 --- a/packages/backend/native-utils/src/model/error.rs +++ b/packages/backend/native-utils/src/model/error.rs @@ -1,4 +1,4 @@ -use crate::impl_into_napi_error; +use crate::impl_napi_error_from; #[derive(thiserror::Error, Debug, PartialEq, Eq)] pub enum Error { @@ -12,4 +12,4 @@ pub enum Error { NotFound, } -impl_into_napi_error!(Error); +impl_napi_error_from!(Error); diff --git a/packages/backend/native-utils/src/util/acct.rs b/packages/backend/native-utils/src/util/acct.rs index 2fcd0df86..cb50d1590 100644 --- a/packages/backend/native-utils/src/util/acct.rs +++ b/packages/backend/native-utils/src/util/acct.rs @@ -1,10 +1,10 @@ -#[cfg_attr(feature = "napi", napi_derive::napi(object))] +#[napi_derive::napi(object)] pub struct Acct { pub username: String, pub host: Option, } -#[cfg_attr(feature = "napi", napi_derive::napi)] +#[napi_derive::napi] pub fn string_to_acct(acct: String) -> Acct { let split: Vec<&str> = if let Some(stripped) = acct.strip_prefix('@') { stripped @@ -24,7 +24,7 @@ pub fn string_to_acct(acct: String) -> Acct { } } -#[cfg_attr(feature = "napi", napi_derive::napi)] +#[napi_derive::napi] pub fn acct_to_string(acct: Acct) -> String { match acct.host { Some(host) => format!("{}@{}", acct.username, host), diff --git a/packages/backend/native-utils/src/util/convert_host.rs b/packages/backend/native-utils/src/util/convert_host.rs index d69201f6c..9f3d47f44 100644 --- a/packages/backend/native-utils/src/util/convert_host.rs +++ b/packages/backend/native-utils/src/util/convert_host.rs @@ -2,7 +2,7 @@ use crate::config::server::read_server_config; use idna; use url::Url; -#[cfg_attr(feature = "napi", napi_derive::napi)] +#[napi_derive::napi] pub fn get_full_ap_account(username: String, host: Option) -> String { if host.is_none() { format!("{}@{}", username, extract_host(read_server_config().url)) @@ -11,7 +11,7 @@ pub fn get_full_ap_account(username: String, host: Option) -> String { } } -#[cfg_attr(feature = "napi", napi_derive::napi)] +#[napi_derive::napi] pub fn is_self_host(host: Option) -> bool { if let Some(x) = host { extract_host(read_server_config().url) == to_puny(x) @@ -20,7 +20,7 @@ pub fn is_self_host(host: Option) -> bool { } } -#[cfg_attr(feature = "napi", napi_derive::napi)] +#[napi_derive::napi] pub fn extract_host(uri: String) -> String { to_puny( Url::parse(uri.as_str()) @@ -31,12 +31,12 @@ pub fn extract_host(uri: String) -> String { ) } -#[cfg_attr(feature = "napi", napi_derive::napi)] +#[napi_derive::napi] pub fn to_puny(host: String) -> String { idna::domain_to_ascii(&host).expect("Failed to encode the host to punycode") } -#[cfg_attr(feature = "napi", napi_derive::napi)] +#[napi_derive::napi] pub fn to_puny_optional(host: Option) -> Option { host.map(to_puny) } diff --git a/packages/backend/native-utils/src/util/convert_to_hidden_post.rs b/packages/backend/native-utils/src/util/convert_to_hidden_post.rs index 3a713f682..d2cb3063c 100644 --- a/packages/backend/native-utils/src/util/convert_to_hidden_post.rs +++ b/packages/backend/native-utils/src/util/convert_to_hidden_post.rs @@ -1,6 +1,6 @@ use napi; -#[cfg_attr(feature = "napi", napi_derive::napi(object))] +#[napi_derive::napi(object)] pub struct Post { pub text: Option, pub cw: Option, @@ -10,7 +10,7 @@ pub struct Post { pub visibility: String, } -#[cfg_attr(feature = "napi", napi_derive::napi)] +#[napi_derive::napi] pub fn convert_to_hidden_post(original_post: Post) -> Post { Post { text: match original_post.text { diff --git a/packages/backend/native-utils/src/util/escape_sql.rs b/packages/backend/native-utils/src/util/escape_sql.rs index 50bc6a64b..21ec9a2ef 100644 --- a/packages/backend/native-utils/src/util/escape_sql.rs +++ b/packages/backend/native-utils/src/util/escape_sql.rs @@ -1,9 +1,9 @@ -#[cfg_attr(feature = "napi", napi_derive::napi)] +#[napi_derive::napi] pub fn sql_like_escape(src: String) -> String { src.replace('%', r"\%").replace('_', r"\_") } -#[cfg_attr(feature = "napi", napi_derive::napi)] +#[napi_derive::napi] pub fn safe_for_sql(src: String) -> bool { !src.contains([ '\0', '\x08', '\x09', '\x1a', '\n', '\r', '"', '\'', '\\', '%', diff --git a/packages/backend/native-utils/src/util/format_milliseconds.rs b/packages/backend/native-utils/src/util/format_milliseconds.rs index b5fbb1e84..ff6389fb7 100644 --- a/packages/backend/native-utils/src/util/format_milliseconds.rs +++ b/packages/backend/native-utils/src/util/format_milliseconds.rs @@ -1,5 +1,5 @@ /// Convert milliseconds to human readable string -#[cfg_attr(feature = "napi", napi_derive::napi)] +#[napi_derive::napi] pub fn format_milliseconds(milliseconds: i32) -> String { let mut seconds = milliseconds / 1000; let mut minutes = seconds / 60; diff --git a/packages/backend/native-utils/src/util/id.rs b/packages/backend/native-utils/src/util/id.rs index 9d1427e65..a5b0ad820 100644 --- a/packages/backend/native-utils/src/util/id.rs +++ b/packages/backend/native-utils/src/util/id.rs @@ -1,18 +1,18 @@ //! ID generation utility based on [cuid2] use basen::BASE36; -use cfg_if::cfg_if; +// use cfg_if::cfg_if; use chrono::Utc; use once_cell::sync::OnceCell; use std::cmp; -use crate::impl_into_napi_error; +use crate::impl_napi_error_from; #[derive(thiserror::Error, Debug, PartialEq, Eq)] #[error("ID generator has not been initialized yet")] pub struct ErrorUninitialized; -impl_into_napi_error!(ErrorUninitialized); +impl_napi_error_from!(ErrorUninitialized); static FINGERPRINT: OnceCell = OnceCell::new(); static GENERATOR: OnceCell = OnceCell::new(); @@ -61,29 +61,29 @@ pub fn get_timestamp(id: &str) -> i64 { } } -cfg_if! { - if #[cfg(feature = "napi")] { - use napi_derive::napi; +// cfg_if! { +// if #[cfg(feature = "napi")] { +use napi_derive::napi; - /// Calls [init_id] inside. Must be called before [native_create_id]. - #[napi] - pub fn native_init_id_generator(length: u16, fingerprint: String) { - init_id(length, &fingerprint); - } - - /// Generates - #[napi] - pub fn native_create_id(date_num: i64) -> String { - create_id(date_num).unwrap() - } - - #[napi] - pub fn native_get_timestamp(id: String) -> i64 { - get_timestamp(&id) - } - } +/// Calls [init_id] inside. Must be called before [native_create_id]. +#[napi] +pub fn native_init_id_generator(length: u16, fingerprint: String) { + init_id(length, &fingerprint); } +/// Generates +#[napi] +pub fn native_create_id(date_num: i64) -> String { + create_id(date_num).unwrap() +} + +#[napi] +pub fn native_get_timestamp(id: String) -> i64 { + get_timestamp(&id) +} +// } +// } + #[cfg(test)] mod unit_test { use crate::util::id; diff --git a/packages/backend/native-utils/src/util/random.rs b/packages/backend/native-utils/src/util/random.rs index 5be649c47..ce0332204 100644 --- a/packages/backend/native-utils/src/util/random.rs +++ b/packages/backend/native-utils/src/util/random.rs @@ -1,7 +1,7 @@ use rand::{distributions::Alphanumeric, thread_rng, Rng}; /// Generate random string based on [thread_rng] and [Alphanumeric]. -#[cfg_attr(feature = "napi", napi_derive::napi)] +#[napi_derive::napi] pub fn gen_string(length: u16) -> String { thread_rng() .sample_iter(Alphanumeric)