fix native import

This commit is contained in:
Namekuji 2023-06-02 15:50:40 -04:00
parent 10072d6e4d
commit 0224824a36
No known key found for this signature in database
GPG Key ID: B541BD6E646CABC7
4 changed files with 20 additions and 22 deletions

View File

@ -70,7 +70,7 @@ cfg_if! {
use crate::model::repository::Repository; use crate::model::repository::Repository;
/// For NAPI because [chrono] is not supported. /// For NAPI because [chrono] is not supported.
#[napi] #[napi(object)]
#[derive(Clone, Debug, PartialEq, Eq, JsonSchema, ToSchema)] #[derive(Clone, Debug, PartialEq, Eq, JsonSchema, ToSchema)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct NativeAntennaSchema { pub struct NativeAntennaSchema {
@ -97,26 +97,22 @@ cfg_if! {
pub has_unread_note: bool, pub has_unread_note: bool,
} }
#[napi] #[napi(string_enum)]
#[derive(Debug, FromStr, PartialEq, Eq, JsonSchema, ToSchema)] #[derive(Debug, FromStr, PartialEq, Eq, JsonSchema, ToSchema)]
#[serde(rename_all = "camelCase")]
#[display(style = "camelCase")]
#[display("'{}'")] #[display("'{}'")]
#[allow(non_camel_case_types)]
pub enum NativeAntennaSrc { pub enum NativeAntennaSrc {
Home, home,
All, all,
Users, users,
List, list,
Group, group,
Instances, instances,
} }
#[napi] #[napi]
impl NativeAntennaSchema { pub async fn native_pack_antenna_by_id(id: String) -> napi::Result<NativeAntennaSchema> {
#[napi] antenna::Model::pack_by_id(id).await.map_err(Into::into)
pub async fn pack_by_id(id: String) -> napi::Result<NativeAntennaSchema> {
antenna::Model::pack_by_id(id).await.map_err(Into::into)
}
} }
} }
} }

View File

@ -1,5 +1,5 @@
import config from "@/config/index.js"; 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 length = Math.min(Math.max(config.cuid?.length ?? 16, 16), 24);
const fingerprint = config.cuid?.fingerprint ?? ""; const fingerprint = config.cuid?.fingerprint ?? "";

View File

@ -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 { export function secureRndstr(length = 32, _ = true): string {
return nativeRandomStr(length); return nativeRandomStr(length);

View File

@ -1,12 +1,14 @@
import { db } from "@/db/postgre.js"; import { db } from "@/db/postgre.js";
import { Antenna } from "@/models/entities/antenna.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({ export const AntennaRepository = db.getRepository(Antenna).extend({
async pack(src: Antenna["id"] | Antenna): Promise<AntennaSchema> { async pack(src: Antenna["id"] | Antenna): Promise<NativeAntennaSchema> {
const id = const id = typeof src === "object" ? src.id : src;
typeof src === "object" ? src.id : src;
return await AntennaSchema.packById(id); return await nativePackAntennaById(id);
}, },
}); });