From 0224824a36b25f89a41a33e89d80d8509b38ae30 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Fri, 2 Jun 2023 15:50:40 -0400 Subject: [PATCH] fix native import --- .../native-utils/src/model/schema/antenna.rs | 26 ++++++++----------- packages/backend/src/misc/gen-id.ts | 2 +- packages/backend/src/misc/secure-rndstr.ts | 2 +- .../src/models/repositories/antenna.ts | 12 +++++---- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/packages/backend/native-utils/src/model/schema/antenna.rs b/packages/backend/native-utils/src/model/schema/antenna.rs index 99521a98b..198230e9a 100644 --- a/packages/backend/native-utils/src/model/schema/antenna.rs +++ b/packages/backend/native-utils/src/model/schema/antenna.rs @@ -70,7 +70,7 @@ cfg_if! { use crate::model::repository::Repository; /// For NAPI because [chrono] is not supported. - #[napi] + #[napi(object)] #[derive(Clone, Debug, PartialEq, Eq, JsonSchema, ToSchema)] #[serde(rename_all = "camelCase")] pub struct NativeAntennaSchema { @@ -97,26 +97,22 @@ cfg_if! { pub has_unread_note: bool, } - #[napi] + #[napi(string_enum)] #[derive(Debug, FromStr, PartialEq, Eq, JsonSchema, ToSchema)] - #[serde(rename_all = "camelCase")] - #[display(style = "camelCase")] #[display("'{}'")] + #[allow(non_camel_case_types)] pub enum NativeAntennaSrc { - Home, - All, - Users, - List, - Group, - Instances, + home, + all, + users, + list, + group, + instances, } #[napi] - impl NativeAntennaSchema { - #[napi] - pub async fn pack_by_id(id: String) -> napi::Result { - antenna::Model::pack_by_id(id).await.map_err(Into::into) - } + pub async fn native_pack_antenna_by_id(id: String) -> napi::Result { + antenna::Model::pack_by_id(id).await.map_err(Into::into) } } } diff --git a/packages/backend/src/misc/gen-id.ts b/packages/backend/src/misc/gen-id.ts index c9e52c829..a016111ca 100644 --- a/packages/backend/src/misc/gen-id.ts +++ b/packages/backend/src/misc/gen-id.ts @@ -1,5 +1,5 @@ import config from "@/config/index.js"; -import { nativeCreateId, nativeInitIdGenerator } from "native-utils/built"; +import { nativeCreateId, nativeInitIdGenerator } from "native-utils/built/index.js"; const length = Math.min(Math.max(config.cuid?.length ?? 16, 16), 24); const fingerprint = config.cuid?.fingerprint ?? ""; diff --git a/packages/backend/src/misc/secure-rndstr.ts b/packages/backend/src/misc/secure-rndstr.ts index 4f4c9884a..3d69a4d4a 100644 --- a/packages/backend/src/misc/secure-rndstr.ts +++ b/packages/backend/src/misc/secure-rndstr.ts @@ -1,4 +1,4 @@ -import { nativeRandomStr } from "native-utils/built"; +import { nativeRandomStr } from "native-utils/built/index.js"; export function secureRndstr(length = 32, _ = true): string { return nativeRandomStr(length); diff --git a/packages/backend/src/models/repositories/antenna.ts b/packages/backend/src/models/repositories/antenna.ts index d9405f4a9..d66aab4ee 100644 --- a/packages/backend/src/models/repositories/antenna.ts +++ b/packages/backend/src/models/repositories/antenna.ts @@ -1,12 +1,14 @@ import { db } from "@/db/postgre.js"; import { Antenna } from "@/models/entities/antenna.js"; -import { AntennaSchema } from "native-utils/built/index.js"; +import { + NativeAntennaSchema, + nativePackAntennaById, +} from "native-utils/built/index.js"; export const AntennaRepository = db.getRepository(Antenna).extend({ - async pack(src: Antenna["id"] | Antenna): Promise { - const id = - typeof src === "object" ? src.id : src; + async pack(src: Antenna["id"] | Antenna): Promise { + const id = typeof src === "object" ? src.id : src; - return await AntennaSchema.packById(id); + return await nativePackAntennaById(id); }, });