chore (backend-rs): make exported enum compatible w/ TypeScript's string enum

This commit is contained in:
naskya 2024-04-19 21:59:12 +09:00
parent c6e2776298
commit 1be5373dfc
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
4 changed files with 79 additions and 79 deletions

View file

@ -17,7 +17,7 @@ regenerate-entities:
attribute=$$(printf 'cfg_attr(feature = "napi", napi_derive::napi(object, js_name = "%s", use_nullable = true))' "$${jsname}"); \ attribute=$$(printf 'cfg_attr(feature = "napi", napi_derive::napi(object, js_name = "%s", use_nullable = true))' "$${jsname}"); \
sed -i "s/NAPI_EXTRA_ATTR_PLACEHOLDER/$${attribute}/" "$${file}"; \ sed -i "s/NAPI_EXTRA_ATTR_PLACEHOLDER/$${attribute}/" "$${file}"; \
done done
sed -i 's/#\[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)\]/#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]\n#[cfg_attr(not(feature = "napi"), derive(Clone))]\n#[cfg_attr(feature = "napi", napi_derive::napi)]/' \ sed -i 's/#\[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)\]/#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]\n#[cfg_attr(not(feature = "napi"), derive(Clone))]\n#[cfg_attr(feature = "napi", napi_derive::napi(string_enum = "camelCase"))]/' \
src/model/entity/sea_orm_active_enums.rs src/model/entity/sea_orm_active_enums.rs
cargo fmt --all -- cargo fmt --all --

View file

@ -772,81 +772,81 @@ export interface ReplyMuting {
muteeId: string muteeId: string
muterId: string muterId: string
} }
export const enum AntennaSrcEnum { export enum AntennaSrcEnum {
All = 0, All = 'all',
Group = 1, Group = 'group',
Home = 2, Home = 'home',
Instances = 3, Instances = 'instances',
List = 4, List = 'list',
Users = 5 Users = 'users'
} }
export const enum MutedNoteReasonEnum { export enum MutedNoteReasonEnum {
Manual = 0, Manual = 'manual',
Other = 1, Other = 'other',
Spam = 2, Spam = 'spam',
Word = 3 Word = 'word'
} }
export const enum NoteVisibilityEnum { export enum NoteVisibilityEnum {
Followers = 0, Followers = 'followers',
Hidden = 1, Hidden = 'hidden',
Home = 2, Home = 'home',
Public = 3, Public = 'public',
Specified = 4 Specified = 'specified'
} }
export const enum NotificationTypeEnum { export enum NotificationTypeEnum {
App = 0, App = 'app',
Follow = 1, Follow = 'follow',
FollowRequestAccepted = 2, FollowRequestAccepted = 'followRequestAccepted',
GroupInvited = 3, GroupInvited = 'groupInvited',
Mention = 4, Mention = 'mention',
PollEnded = 5, PollEnded = 'pollEnded',
PollVote = 6, PollVote = 'pollVote',
Quote = 7, Quote = 'quote',
Reaction = 8, Reaction = 'reaction',
ReceiveFollowRequest = 9, ReceiveFollowRequest = 'receiveFollowRequest',
Renote = 10, Renote = 'renote',
Reply = 11 Reply = 'reply'
} }
export const enum PageVisibilityEnum { export enum PageVisibilityEnum {
Followers = 0, Followers = 'followers',
Public = 1, Public = 'public',
Specified = 2 Specified = 'specified'
} }
export const enum PollNotevisibilityEnum { export enum PollNotevisibilityEnum {
Followers = 0, Followers = 'followers',
Home = 1, Home = 'home',
Public = 2, Public = 'public',
Specified = 3 Specified = 'specified'
} }
export const enum RelayStatusEnum { export enum RelayStatusEnum {
Accepted = 0, Accepted = 'accepted',
Rejected = 1, Rejected = 'rejected',
Requesting = 2 Requesting = 'requesting'
} }
export const enum UserEmojimodpermEnum { export enum UserEmojimodpermEnum {
Add = 0, Add = 'add',
Full = 1, Full = 'full',
Mod = 2, Mod = 'mod',
Unauthorized = 3 Unauthorized = 'unauthorized'
} }
export const enum UserProfileFfvisibilityEnum { export enum UserProfileFfvisibilityEnum {
Followers = 0, Followers = 'followers',
Private = 1, Private = 'private',
Public = 2 Public = 'public'
} }
export const enum UserProfileMutingnotificationtypesEnum { export enum UserProfileMutingnotificationtypesEnum {
App = 0, App = 'app',
Follow = 1, Follow = 'follow',
FollowRequestAccepted = 2, FollowRequestAccepted = 'followRequestAccepted',
GroupInvited = 3, GroupInvited = 'groupInvited',
Mention = 4, Mention = 'mention',
PollEnded = 5, PollEnded = 'pollEnded',
PollVote = 6, PollVote = 'pollVote',
Quote = 7, Quote = 'quote',
Reaction = 8, Reaction = 'reaction',
ReceiveFollowRequest = 9, ReceiveFollowRequest = 'receiveFollowRequest',
Renote = 10, Renote = 'renote',
Reply = 11 Reply = 'reply'
} }
export interface Signin { export interface Signin {
id: string id: string

View file

@ -33,8 +33,8 @@
}, },
"scripts": { "scripts": {
"artifacts": "napi artifacts", "artifacts": "napi artifacts",
"build": "napi build --features napi --platform --release ./built/", "build": "napi build --features napi --no-const-enum --platform --release ./built/",
"build:debug": "napi build --features napi --platform ./built/", "build:debug": "napi build --features napi --no-const-enum --platform ./built/",
"prepublishOnly": "napi prepublish -t npm", "prepublishOnly": "napi prepublish -t npm",
"test": "pnpm run cargo:test && pnpm run build:debug && ava", "test": "pnpm run cargo:test && pnpm run build:debug && ava",
"universal": "napi universal", "universal": "napi universal",

View file

@ -4,7 +4,7 @@ use sea_orm::entity::prelude::*;
#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] #[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[cfg_attr(not(feature = "napi"), derive(Clone))] #[cfg_attr(not(feature = "napi"), derive(Clone))]
#[cfg_attr(feature = "napi", napi_derive::napi)] #[cfg_attr(feature = "napi", napi_derive::napi(string_enum = "camelCase"))]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "antenna_src_enum")] #[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "antenna_src_enum")]
pub enum AntennaSrcEnum { pub enum AntennaSrcEnum {
#[sea_orm(string_value = "all")] #[sea_orm(string_value = "all")]
@ -22,7 +22,7 @@ pub enum AntennaSrcEnum {
} }
#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] #[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[cfg_attr(not(feature = "napi"), derive(Clone))] #[cfg_attr(not(feature = "napi"), derive(Clone))]
#[cfg_attr(feature = "napi", napi_derive::napi)] #[cfg_attr(feature = "napi", napi_derive::napi(string_enum = "camelCase"))]
#[sea_orm( #[sea_orm(
rs_type = "String", rs_type = "String",
db_type = "Enum", db_type = "Enum",
@ -40,7 +40,7 @@ pub enum MutedNoteReasonEnum {
} }
#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] #[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[cfg_attr(not(feature = "napi"), derive(Clone))] #[cfg_attr(not(feature = "napi"), derive(Clone))]
#[cfg_attr(feature = "napi", napi_derive::napi)] #[cfg_attr(feature = "napi", napi_derive::napi(string_enum = "camelCase"))]
#[sea_orm( #[sea_orm(
rs_type = "String", rs_type = "String",
db_type = "Enum", db_type = "Enum",
@ -60,7 +60,7 @@ pub enum NoteVisibilityEnum {
} }
#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] #[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[cfg_attr(not(feature = "napi"), derive(Clone))] #[cfg_attr(not(feature = "napi"), derive(Clone))]
#[cfg_attr(feature = "napi", napi_derive::napi)] #[cfg_attr(feature = "napi", napi_derive::napi(string_enum = "camelCase"))]
#[sea_orm( #[sea_orm(
rs_type = "String", rs_type = "String",
db_type = "Enum", db_type = "Enum",
@ -94,7 +94,7 @@ pub enum NotificationTypeEnum {
} }
#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] #[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[cfg_attr(not(feature = "napi"), derive(Clone))] #[cfg_attr(not(feature = "napi"), derive(Clone))]
#[cfg_attr(feature = "napi", napi_derive::napi)] #[cfg_attr(feature = "napi", napi_derive::napi(string_enum = "camelCase"))]
#[sea_orm( #[sea_orm(
rs_type = "String", rs_type = "String",
db_type = "Enum", db_type = "Enum",
@ -110,7 +110,7 @@ pub enum PageVisibilityEnum {
} }
#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] #[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[cfg_attr(not(feature = "napi"), derive(Clone))] #[cfg_attr(not(feature = "napi"), derive(Clone))]
#[cfg_attr(feature = "napi", napi_derive::napi)] #[cfg_attr(feature = "napi", napi_derive::napi(string_enum = "camelCase"))]
#[sea_orm( #[sea_orm(
rs_type = "String", rs_type = "String",
db_type = "Enum", db_type = "Enum",
@ -128,7 +128,7 @@ pub enum PollNotevisibilityEnum {
} }
#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] #[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[cfg_attr(not(feature = "napi"), derive(Clone))] #[cfg_attr(not(feature = "napi"), derive(Clone))]
#[cfg_attr(feature = "napi", napi_derive::napi)] #[cfg_attr(feature = "napi", napi_derive::napi(string_enum = "camelCase"))]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "relay_status_enum")] #[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "relay_status_enum")]
pub enum RelayStatusEnum { pub enum RelayStatusEnum {
#[sea_orm(string_value = "accepted")] #[sea_orm(string_value = "accepted")]
@ -140,7 +140,7 @@ pub enum RelayStatusEnum {
} }
#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] #[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[cfg_attr(not(feature = "napi"), derive(Clone))] #[cfg_attr(not(feature = "napi"), derive(Clone))]
#[cfg_attr(feature = "napi", napi_derive::napi)] #[cfg_attr(feature = "napi", napi_derive::napi(string_enum = "camelCase"))]
#[sea_orm( #[sea_orm(
rs_type = "String", rs_type = "String",
db_type = "Enum", db_type = "Enum",
@ -158,7 +158,7 @@ pub enum UserEmojimodpermEnum {
} }
#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] #[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[cfg_attr(not(feature = "napi"), derive(Clone))] #[cfg_attr(not(feature = "napi"), derive(Clone))]
#[cfg_attr(feature = "napi", napi_derive::napi)] #[cfg_attr(feature = "napi", napi_derive::napi(string_enum = "camelCase"))]
#[sea_orm( #[sea_orm(
rs_type = "String", rs_type = "String",
db_type = "Enum", db_type = "Enum",
@ -174,7 +174,7 @@ pub enum UserProfileFfvisibilityEnum {
} }
#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)] #[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[cfg_attr(not(feature = "napi"), derive(Clone))] #[cfg_attr(not(feature = "napi"), derive(Clone))]
#[cfg_attr(feature = "napi", napi_derive::napi)] #[cfg_attr(feature = "napi", napi_derive::napi(string_enum = "camelCase"))]
#[sea_orm( #[sea_orm(
rs_type = "String", rs_type = "String",
db_type = "Enum", db_type = "Enum",