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;
/// 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<NativeAntennaSchema> {
antenna::Model::pack_by_id(id).await.map_err(Into::into)
}
pub async fn native_pack_antenna_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 { 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 ?? "";

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 {
return nativeRandomStr(length);

View File

@ -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<AntennaSchema> {
const id =
typeof src === "object" ? src.id : src;
async pack(src: Antenna["id"] | Antenna): Promise<NativeAntennaSchema> {
const id = typeof src === "object" ? src.id : src;
return await AntennaSchema.packById(id);
return await nativePackAntennaById(id);
},
});