1
0
Fork 1
mirror of https://example.com synced 2024-11-22 12:06:39 +09:00

refactor: make database models accesible to napi

Co-authored-by: sup39 <dev@sup39.dev>
This commit is contained in:
naskya 2024-01-20 05:57:00 +09:00
parent 0bb23cb8db
commit 45daf59880
Signed by: naskya
GPG key ID: 712D413B3A9FED5C
84 changed files with 181 additions and 68 deletions

View file

@ -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:

View file

@ -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;

View file

@ -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",
]

View file

@ -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"

View file

@ -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);

View file

@ -4,5 +4,5 @@ pub mod macros;
pub mod model;
pub mod util;
#[cfg(feature = "napi")]
// #[cfg(feature = "napi")]
pub mod mastodon_api;

View file

@ -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<napi::Error> 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())
}
}
};

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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",

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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);

View file

@ -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<String>,
}
#[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),

View file

@ -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>) -> 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>) -> String {
}
}
#[cfg_attr(feature = "napi", napi_derive::napi)]
#[napi_derive::napi]
pub fn is_self_host(host: Option<String>) -> 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<String>) -> 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<String>) -> Option<String> {
host.map(to_puny)
}

View file

@ -1,6 +1,6 @@
use napi;
#[cfg_attr(feature = "napi", napi_derive::napi(object))]
#[napi_derive::napi(object)]
pub struct Post {
pub text: Option<String>,
pub cw: Option<String>,
@ -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 {

View file

@ -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', '"', '\'', '\\', '%',

View file

@ -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;

View file

@ -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<String> = OnceCell::new();
static GENERATOR: OnceCell<cuid2::CuidConstructor> = 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;

View file

@ -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)