From 3af4a86254ccf67b7a0c2060bf55013776500c77 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Fri, 2 Jun 2023 09:55:57 -0400 Subject: [PATCH] use schema in native-utils --- packages/backend/native-utils/package.json | 8 ++--- packages/backend/package.json | 2 +- .../src/models/repositories/antenna.ts | 34 +++---------------- pnpm-workspace.yaml | 1 + 4 files changed, 11 insertions(+), 34 deletions(-) diff --git a/packages/backend/native-utils/package.json b/packages/backend/native-utils/package.json index aa194bad3..f1ea2c9b4 100644 --- a/packages/backend/native-utils/package.json +++ b/packages/backend/native-utils/package.json @@ -23,8 +23,8 @@ }, "license": "MIT", "devDependencies": { - "@napi-rs/cli": "^2.15.0", - "ava": "^5.1.1" + "@napi-rs/cli": "2.15.0", + "ava": "5.1.1" }, "ava": { "timeout": "3m" @@ -40,7 +40,7 @@ "test": "ava", "universal": "napi universal", "version": "napi version", - "cargo:unit": "cargo test --workspace unit_test", - "cargo:integration": "cargo test --workspace int_test -- --test-threads=1" + "cargo:unit": "cargo test unit_test", + "cargo:integration": "cargo test --no-default-features int_test -- --test-threads=1" } } diff --git a/packages/backend/package.json b/packages/backend/package.json index c084d67bc..0b0315a06 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -9,7 +9,7 @@ "migrate": "typeorm migration:run -d ormconfig.js", "revertmigration": "typeorm migration:revert -d ormconfig.js", "check:connect": "node ./check_connect.js", - "build": "napi build --platform --release --cargo-cwd native-utils ./native-utils/built/ && pnpm swc src -d built -D", + "build": "pnpm swc src -d built -D", "watch": "pnpm swc src -d built -D -w", "lint": "pnpm rome check \"src/**/*.ts\"", "mocha": "cross-env NODE_ENV=test TS_NODE_FILES=true TS_NODE_TRANSPILE_ONLY=true TS_NODE_PROJECT=\"./test/tsconfig.json\" mocha", diff --git a/packages/backend/src/models/repositories/antenna.ts b/packages/backend/src/models/repositories/antenna.ts index c325e2589..d9405f4a9 100644 --- a/packages/backend/src/models/repositories/antenna.ts +++ b/packages/backend/src/models/repositories/antenna.ts @@ -1,36 +1,12 @@ import { db } from "@/db/postgre.js"; import { Antenna } from "@/models/entities/antenna.js"; -import type { Packed } from "@/misc/schema.js"; -import { AntennaNotes, UserGroupJoinings } from "../index.js"; +import { AntennaSchema } from "native-utils/built/index.js"; export const AntennaRepository = db.getRepository(Antenna).extend({ - async pack(src: Antenna["id"] | Antenna): Promise> { - const antenna = - typeof src === "object" ? src : await this.findOneByOrFail({ id: src }); + async pack(src: Antenna["id"] | Antenna): Promise { + const id = + typeof src === "object" ? src.id : src; - const hasUnreadNote = - (await AntennaNotes.findOneBy({ antennaId: antenna.id, read: false })) != - null; - const userGroupJoining = antenna.userGroupJoiningId - ? await UserGroupJoinings.findOneBy({ id: antenna.userGroupJoiningId }) - : null; - - return { - id: antenna.id, - createdAt: antenna.createdAt.toISOString(), - name: antenna.name, - keywords: antenna.keywords, - excludeKeywords: antenna.excludeKeywords, - src: antenna.src, - userListId: antenna.userListId, - userGroupId: userGroupJoining ? userGroupJoining.userGroupId : null, - users: antenna.users, - instances: antenna.instances, - caseSensitive: antenna.caseSensitive, - notify: antenna.notify, - withReplies: antenna.withReplies, - withFile: antenna.withFile, - hasUnreadNote, - }; + return await AntennaSchema.packById(id); }, }); diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index a2ebb0465..2bf4474f0 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,5 +1,6 @@ packages: - 'packages/backend' + - 'packages/backend/native-utils' - 'packages/client' - 'packages/sw' - 'packages/calckey-js'