use schema in native-utils

This commit is contained in:
Namekuji 2023-06-02 09:55:57 -04:00
parent bc209143e6
commit 3af4a86254
4 changed files with 11 additions and 34 deletions

View file

@ -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"
}
}

View file

@ -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",

View file

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

View file

@ -1,5 +1,6 @@
packages:
- 'packages/backend'
- 'packages/backend/native-utils'
- 'packages/client'
- 'packages/sw'
- 'packages/calckey-js'