From 511ff69900ab88f38ffca3a4f805647927eebb85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BE=E3=81=A3=E3=81=A1=E3=82=83=E3=81=A8=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=82=85?= <17376330+u1-liquid@users.noreply.github.com> Date: Wed, 11 Oct 2023 11:28:48 +0900 Subject: [PATCH] =?UTF-8?q?EntityService=20=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/core/entities/AppEntityService.ts | 6 ++-- .../core/entities/BlockingEntityService.ts | 2 +- .../src/core/entities/ChannelEntityService.ts | 1 - .../src/core/entities/ClipEntityService.ts | 1 - .../core/entities/DriveFolderEntityService.ts | 1 - .../src/core/entities/EmojiEntityService.ts | 1 - .../src/core/entities/FlashEntityService.ts | 1 - .../core/entities/FlashLikeEntityService.ts | 1 - .../entities/FollowRequestEntityService.ts | 1 - .../core/entities/FollowingEntityService.ts | 1 - .../core/entities/GalleryLikeEntityService.ts | 1 - .../core/entities/GalleryPostEntityService.ts | 1 - .../src/core/entities/HashtagEntityService.ts | 1 - .../core/entities/InstanceEntityService.ts | 1 - .../entities/ModerationLogEntityService.ts | 1 - .../src/core/entities/MutingEntityService.ts | 1 - .../entities/NoteFavoriteEntityService.ts | 1 - .../entities/NoteReactionEntityService.ts | 1 - .../src/core/entities/PageEntityService.ts | 1 - .../core/entities/PageLikeEntityService.ts | 1 - .../entities/RenoteMutingEntityService.ts | 1 - .../src/core/entities/SigninEntityService.ts | 1 - .../src/core/entities/UserEntityService.ts | 2 +- .../core/entities/UserListEntityService.ts | 29 ++++++++++------ packages/backend/src/misc/json-schema.ts | 6 ++-- .../src/models/json-schema/user-list.ts | 33 +++++++++++++++++++ 26 files changed, 60 insertions(+), 38 deletions(-) diff --git a/packages/backend/src/core/entities/AppEntityService.ts b/packages/backend/src/core/entities/AppEntityService.ts index 8fec971d75..9d612d861a 100644 --- a/packages/backend/src/core/entities/AppEntityService.ts +++ b/packages/backend/src/core/entities/AppEntityService.ts @@ -32,11 +32,11 @@ export class AppEntityService { includeProfileImageIds?: boolean }, ): Promise> { - const opts = Object.assign({ + const opts = { detail: false, includeSecret: false, - includeProfileImageIds: false, - }, options); + includeProfileImageIds: false, ...options + }; const app = typeof src === 'object' ? src : await this.appsRepository.findOneByOrFail({ id: src }); diff --git a/packages/backend/src/core/entities/BlockingEntityService.ts b/packages/backend/src/core/entities/BlockingEntityService.ts index 82ee71a2dc..647b796d87 100644 --- a/packages/backend/src/core/entities/BlockingEntityService.ts +++ b/packages/backend/src/core/entities/BlockingEntityService.ts @@ -43,7 +43,7 @@ export class BlockingEntityService { @bindThis public async packMany( blockings: (MiBlocking['id'] | MiBlocking)[], - me: { id: MiUser['id'] }, + me: { id: MiUser['id'] } | null | undefined, ) : Promise[]> { return (await Promise.allSettled(blockings.map(x => this.pack(x, me)))) .filter(result => result.status === 'fulfilled') diff --git a/packages/backend/src/core/entities/ChannelEntityService.ts b/packages/backend/src/core/entities/ChannelEntityService.ts index 7972a06dc5..a416a53090 100644 --- a/packages/backend/src/core/entities/ChannelEntityService.ts +++ b/packages/backend/src/core/entities/ChannelEntityService.ts @@ -8,7 +8,6 @@ import { In } from 'typeorm'; import { DI } from '@/di-symbols.js'; import type { ChannelFavoritesRepository, ChannelFollowingsRepository, ChannelsRepository, DriveFilesRepository, NoteUnreadsRepository, NotesRepository } from '@/models/_.js'; import type { Packed } from '@/misc/json-schema.js'; -import type { } from '@/models/Blocking.js'; import type { MiUser } from '@/models/User.js'; import type { MiChannel } from '@/models/Channel.js'; import { bindThis } from '@/decorators.js'; diff --git a/packages/backend/src/core/entities/ClipEntityService.ts b/packages/backend/src/core/entities/ClipEntityService.ts index 4e6adc0db4..e220aa3b18 100644 --- a/packages/backend/src/core/entities/ClipEntityService.ts +++ b/packages/backend/src/core/entities/ClipEntityService.ts @@ -8,7 +8,6 @@ import { DI } from '@/di-symbols.js'; import type { ClipFavoritesRepository, ClipsRepository, MiUser } from '@/models/_.js'; import { awaitAll } from '@/misc/prelude/await-all.js'; import type { Packed } from '@/misc/json-schema.js'; -import type { } from '@/models/Blocking.js'; import type { MiClip } from '@/models/Clip.js'; import { bindThis } from '@/decorators.js'; import { UserEntityService } from './UserEntityService.js'; diff --git a/packages/backend/src/core/entities/DriveFolderEntityService.ts b/packages/backend/src/core/entities/DriveFolderEntityService.ts index 55014284bd..5c953963f8 100644 --- a/packages/backend/src/core/entities/DriveFolderEntityService.ts +++ b/packages/backend/src/core/entities/DriveFolderEntityService.ts @@ -8,7 +8,6 @@ import { DI } from '@/di-symbols.js'; import type { DriveFilesRepository, DriveFoldersRepository } from '@/models/_.js'; import { awaitAll } from '@/misc/prelude/await-all.js'; import type { Packed } from '@/misc/json-schema.js'; -import type { } from '@/models/Blocking.js'; import type { MiDriveFolder } from '@/models/DriveFolder.js'; import { bindThis } from '@/decorators.js'; diff --git a/packages/backend/src/core/entities/EmojiEntityService.ts b/packages/backend/src/core/entities/EmojiEntityService.ts index 57b9b3a6c6..ea03a11afd 100644 --- a/packages/backend/src/core/entities/EmojiEntityService.ts +++ b/packages/backend/src/core/entities/EmojiEntityService.ts @@ -7,7 +7,6 @@ import { Inject, Injectable } from '@nestjs/common'; import { DI } from '@/di-symbols.js'; import type { EmojisRepository } from '@/models/_.js'; import type { Packed } from '@/misc/json-schema.js'; -import type { } from '@/models/Blocking.js'; import type { MiEmoji } from '@/models/Emoji.js'; import { bindThis } from '@/decorators.js'; diff --git a/packages/backend/src/core/entities/FlashEntityService.ts b/packages/backend/src/core/entities/FlashEntityService.ts index 1219c1c138..8a169a46a2 100644 --- a/packages/backend/src/core/entities/FlashEntityService.ts +++ b/packages/backend/src/core/entities/FlashEntityService.ts @@ -8,7 +8,6 @@ import { DI } from '@/di-symbols.js'; import type { FlashsRepository, FlashLikesRepository } from '@/models/_.js'; import { awaitAll } from '@/misc/prelude/await-all.js'; import type { Packed } from '@/misc/json-schema.js'; -import type { } from '@/models/Blocking.js'; import type { MiUser } from '@/models/User.js'; import type { MiFlash } from '@/models/Flash.js'; import { bindThis } from '@/decorators.js'; diff --git a/packages/backend/src/core/entities/FlashLikeEntityService.ts b/packages/backend/src/core/entities/FlashLikeEntityService.ts index fe4539627c..1e44b123dd 100644 --- a/packages/backend/src/core/entities/FlashLikeEntityService.ts +++ b/packages/backend/src/core/entities/FlashLikeEntityService.ts @@ -6,7 +6,6 @@ import { Inject, Injectable } from '@nestjs/common'; import { DI } from '@/di-symbols.js'; import type { FlashLikesRepository } from '@/models/_.js'; -import type { } from '@/models/Blocking.js'; import type { MiUser } from '@/models/User.js'; import type { MiFlashLike } from '@/models/FlashLike.js'; import { bindThis } from '@/decorators.js'; diff --git a/packages/backend/src/core/entities/FollowRequestEntityService.ts b/packages/backend/src/core/entities/FollowRequestEntityService.ts index 2e3243e8dd..d35c3d6523 100644 --- a/packages/backend/src/core/entities/FollowRequestEntityService.ts +++ b/packages/backend/src/core/entities/FollowRequestEntityService.ts @@ -6,7 +6,6 @@ import { Inject, Injectable } from '@nestjs/common'; import { DI } from '@/di-symbols.js'; import type { FollowRequestsRepository } from '@/models/_.js'; -import type { } from '@/models/Blocking.js'; import type { MiUser } from '@/models/User.js'; import type { MiFollowRequest } from '@/models/FollowRequest.js'; import { bindThis } from '@/decorators.js'; diff --git a/packages/backend/src/core/entities/FollowingEntityService.ts b/packages/backend/src/core/entities/FollowingEntityService.ts index c3ca8dfbb4..b89548ef70 100644 --- a/packages/backend/src/core/entities/FollowingEntityService.ts +++ b/packages/backend/src/core/entities/FollowingEntityService.ts @@ -8,7 +8,6 @@ import { DI } from '@/di-symbols.js'; import type { FollowingsRepository } from '@/models/_.js'; import { awaitAll } from '@/misc/prelude/await-all.js'; import type { Packed } from '@/misc/json-schema.js'; -import type { } from '@/models/Blocking.js'; import type { MiUser } from '@/models/User.js'; import type { MiFollowing } from '@/models/Following.js'; import { bindThis } from '@/decorators.js'; diff --git a/packages/backend/src/core/entities/GalleryLikeEntityService.ts b/packages/backend/src/core/entities/GalleryLikeEntityService.ts index 51a25d3aae..b3f3b3faeb 100644 --- a/packages/backend/src/core/entities/GalleryLikeEntityService.ts +++ b/packages/backend/src/core/entities/GalleryLikeEntityService.ts @@ -6,7 +6,6 @@ import { Inject, Injectable } from '@nestjs/common'; import { DI } from '@/di-symbols.js'; import type { GalleryLikesRepository } from '@/models/_.js'; -import type { } from '@/models/Blocking.js'; import type { MiGalleryLike } from '@/models/GalleryLike.js'; import { bindThis } from '@/decorators.js'; import { Packed } from '@/misc/json-schema.js'; diff --git a/packages/backend/src/core/entities/GalleryPostEntityService.ts b/packages/backend/src/core/entities/GalleryPostEntityService.ts index 19a80270ed..b8f242c379 100644 --- a/packages/backend/src/core/entities/GalleryPostEntityService.ts +++ b/packages/backend/src/core/entities/GalleryPostEntityService.ts @@ -8,7 +8,6 @@ import { DI } from '@/di-symbols.js'; import type { GalleryLikesRepository, GalleryPostsRepository } from '@/models/_.js'; import { awaitAll } from '@/misc/prelude/await-all.js'; import type { Packed } from '@/misc/json-schema.js'; -import type { } from '@/models/Blocking.js'; import type { MiUser } from '@/models/User.js'; import type { MiGalleryPost } from '@/models/GalleryPost.js'; import { bindThis } from '@/decorators.js'; diff --git a/packages/backend/src/core/entities/HashtagEntityService.ts b/packages/backend/src/core/entities/HashtagEntityService.ts index d8cca2b2a2..a70865f810 100644 --- a/packages/backend/src/core/entities/HashtagEntityService.ts +++ b/packages/backend/src/core/entities/HashtagEntityService.ts @@ -5,7 +5,6 @@ import { Injectable } from '@nestjs/common'; import type { Packed } from '@/misc/json-schema.js'; -import type { } from '@/models/Blocking.js'; import type { MiHashtag } from '@/models/Hashtag.js'; import { bindThis } from '@/decorators.js'; diff --git a/packages/backend/src/core/entities/InstanceEntityService.ts b/packages/backend/src/core/entities/InstanceEntityService.ts index 6f3191adea..7b458d2e5c 100644 --- a/packages/backend/src/core/entities/InstanceEntityService.ts +++ b/packages/backend/src/core/entities/InstanceEntityService.ts @@ -5,7 +5,6 @@ import { Injectable } from '@nestjs/common'; import type { Packed } from '@/misc/json-schema.js'; -import type { } from '@/models/Blocking.js'; import type { MiInstance } from '@/models/Instance.js'; import { MetaService } from '@/core/MetaService.js'; import { bindThis } from '@/decorators.js'; diff --git a/packages/backend/src/core/entities/ModerationLogEntityService.ts b/packages/backend/src/core/entities/ModerationLogEntityService.ts index f05d7b2fd7..86d3ab1be5 100644 --- a/packages/backend/src/core/entities/ModerationLogEntityService.ts +++ b/packages/backend/src/core/entities/ModerationLogEntityService.ts @@ -7,7 +7,6 @@ import { Inject, Injectable } from '@nestjs/common'; import { DI } from '@/di-symbols.js'; import type { ModerationLogsRepository } from '@/models/_.js'; import { awaitAll } from '@/misc/prelude/await-all.js'; -import type { } from '@/models/Blocking.js'; import type { MiUser } from '@/models/User.js'; import type { MiModerationLog } from '@/models/ModerationLog.js'; import { bindThis } from '@/decorators.js'; diff --git a/packages/backend/src/core/entities/MutingEntityService.ts b/packages/backend/src/core/entities/MutingEntityService.ts index 6f9a6ffebc..34981891d6 100644 --- a/packages/backend/src/core/entities/MutingEntityService.ts +++ b/packages/backend/src/core/entities/MutingEntityService.ts @@ -8,7 +8,6 @@ import { DI } from '@/di-symbols.js'; import type { MutingsRepository } from '@/models/_.js'; import { awaitAll } from '@/misc/prelude/await-all.js'; import type { Packed } from '@/misc/json-schema.js'; -import type { } from '@/models/Blocking.js'; import type { MiUser } from '@/models/User.js'; import type { MiMuting } from '@/models/Muting.js'; import { bindThis } from '@/decorators.js'; diff --git a/packages/backend/src/core/entities/NoteFavoriteEntityService.ts b/packages/backend/src/core/entities/NoteFavoriteEntityService.ts index 33ba397e20..112433ed39 100644 --- a/packages/backend/src/core/entities/NoteFavoriteEntityService.ts +++ b/packages/backend/src/core/entities/NoteFavoriteEntityService.ts @@ -6,7 +6,6 @@ import { Inject, Injectable } from '@nestjs/common'; import { DI } from '@/di-symbols.js'; import type { NoteFavoritesRepository } from '@/models/_.js'; -import type { } from '@/models/Blocking.js'; import type { MiUser } from '@/models/User.js'; import type { MiNoteFavorite } from '@/models/NoteFavorite.js'; import { bindThis } from '@/decorators.js'; diff --git a/packages/backend/src/core/entities/NoteReactionEntityService.ts b/packages/backend/src/core/entities/NoteReactionEntityService.ts index fcfb90c946..a498b09bb2 100644 --- a/packages/backend/src/core/entities/NoteReactionEntityService.ts +++ b/packages/backend/src/core/entities/NoteReactionEntityService.ts @@ -10,7 +10,6 @@ import type { NoteReactionsRepository } from '@/models/_.js'; import type { Packed } from '@/misc/json-schema.js'; import { bindThis } from '@/decorators.js'; import type { OnModuleInit } from '@nestjs/common'; -import type { } from '@/models/Blocking.js'; import type { MiUser } from '@/models/User.js'; import type { MiNoteReaction } from '@/models/NoteReaction.js'; import type { ReactionService } from '../ReactionService.js'; diff --git a/packages/backend/src/core/entities/PageEntityService.ts b/packages/backend/src/core/entities/PageEntityService.ts index 092f66e255..b7317efb39 100644 --- a/packages/backend/src/core/entities/PageEntityService.ts +++ b/packages/backend/src/core/entities/PageEntityService.ts @@ -8,7 +8,6 @@ import { DI } from '@/di-symbols.js'; import type { DriveFilesRepository, PagesRepository, PageLikesRepository } from '@/models/_.js'; import { awaitAll } from '@/misc/prelude/await-all.js'; import type { Packed } from '@/misc/json-schema.js'; -import type { } from '@/models/Blocking.js'; import type { MiUser } from '@/models/User.js'; import type { MiPage } from '@/models/Page.js'; import type { MiDriveFile } from '@/models/DriveFile.js'; diff --git a/packages/backend/src/core/entities/PageLikeEntityService.ts b/packages/backend/src/core/entities/PageLikeEntityService.ts index c5200bb82d..6de5750f5e 100644 --- a/packages/backend/src/core/entities/PageLikeEntityService.ts +++ b/packages/backend/src/core/entities/PageLikeEntityService.ts @@ -6,7 +6,6 @@ import { Inject, Injectable } from '@nestjs/common'; import { DI } from '@/di-symbols.js'; import type { PageLikesRepository } from '@/models/_.js'; -import type { } from '@/models/Blocking.js'; import type { MiUser } from '@/models/User.js'; import type { MiPageLike } from '@/models/PageLike.js'; import { bindThis } from '@/decorators.js'; diff --git a/packages/backend/src/core/entities/RenoteMutingEntityService.ts b/packages/backend/src/core/entities/RenoteMutingEntityService.ts index 5c6e025bb2..8893b2921d 100644 --- a/packages/backend/src/core/entities/RenoteMutingEntityService.ts +++ b/packages/backend/src/core/entities/RenoteMutingEntityService.ts @@ -8,7 +8,6 @@ import { DI } from '@/di-symbols.js'; import type { RenoteMutingsRepository } from '@/models/_.js'; import { awaitAll } from '@/misc/prelude/await-all.js'; import type { Packed } from '@/misc/json-schema.js'; -import type { } from '@/models/Blocking.js'; import type { MiUser } from '@/models/User.js'; import type { MiRenoteMuting } from '@/models/RenoteMuting.js'; import { bindThis } from '@/decorators.js'; diff --git a/packages/backend/src/core/entities/SigninEntityService.ts b/packages/backend/src/core/entities/SigninEntityService.ts index 8c88e8560a..6aaee0531f 100644 --- a/packages/backend/src/core/entities/SigninEntityService.ts +++ b/packages/backend/src/core/entities/SigninEntityService.ts @@ -4,7 +4,6 @@ */ import { Injectable } from '@nestjs/common'; -import type { } from '@/models/Blocking.js'; import type { MiSignin } from '@/models/Signin.js'; import { bindThis } from '@/decorators.js'; diff --git a/packages/backend/src/core/entities/UserEntityService.ts b/packages/backend/src/core/entities/UserEntityService.ts index 405fbeebeb..18ff7c1d80 100644 --- a/packages/backend/src/core/entities/UserEntityService.ts +++ b/packages/backend/src/core/entities/UserEntityService.ts @@ -289,7 +289,7 @@ export class UserEntityService implements OnModuleInit { public async pack( src: MiUser['id'] | MiUser, - me: { id: MiUser['id']; } | null | undefined, + me: { id: MiUser['id'] } | null | undefined, options?: { detail?: D, includeSecrets?: boolean, diff --git a/packages/backend/src/core/entities/UserListEntityService.ts b/packages/backend/src/core/entities/UserListEntityService.ts index 46cb4f05ab..7511481f4f 100644 --- a/packages/backend/src/core/entities/UserListEntityService.ts +++ b/packages/backend/src/core/entities/UserListEntityService.ts @@ -7,7 +7,6 @@ import { Inject, Injectable } from '@nestjs/common'; import { DI } from '@/di-symbols.js'; import type { MiUser, MiUserListMembership, UserListMembershipsRepository, UserListsRepository } from '@/models/_.js'; import type { Packed } from '@/misc/json-schema.js'; -import type { } from '@/models/Blocking.js'; import type { MiUserList } from '@/models/UserList.js'; import { bindThis } from '@/decorators.js'; import { UserEntityService } from './UserEntityService.js'; @@ -44,18 +43,28 @@ export class UserListEntityService { }; } + @bindThis + public async packMemberships( + src: MiUserListMembership, + me: { id: MiUser['id'] } | null | undefined, + ): Promise> { + return { + id: src.id, + createdAt: src.createdAt.toISOString(), + userId: src.userId, + user: await this.userEntityService.pack(src.userId, me), + withReplies: src.withReplies, + }; + } + @bindThis public async packMembershipsMany( memberships: MiUserListMembership[], - me: { id: MiUser['id']; } | null | undefined, - ) { - return Promise.all(memberships.map(async x => ({ - id: x.id, - createdAt: x.createdAt.toISOString(), - userId: x.userId, - user: await this.userEntityService.pack(x.userId, me), - withReplies: x.withReplies, - }))); + me: { id: MiUser['id'] } | null | undefined, + ): Promise[]> { + return (await Promise.allSettled(memberships.map(u => this.packMemberships(u, me)))) + .filter(result => result.status === 'fulfilled') + .map(result => (result as PromiseFulfilledResult>).value); } } diff --git a/packages/backend/src/misc/json-schema.ts b/packages/backend/src/misc/json-schema.ts index 0d62694670..093168202c 100644 --- a/packages/backend/src/misc/json-schema.ts +++ b/packages/backend/src/misc/json-schema.ts @@ -21,7 +21,7 @@ import { packedClipSchema } from '@/models/json-schema/clip.js'; import { packedDriveFileSchema } from '@/models/json-schema/drive-file.js'; import { packedDriveFolderSchema } from '@/models/json-schema/drive-folder.js'; import { packedFederationInstanceSchema } from '@/models/json-schema/federation-instance.js'; -import { packedFlashLikeSchema } from '@/models/json-schema/flash.js'; +import { packedFlashLikeSchema, packedFlashSchema } from '@/models/json-schema/flash.js'; import { packedFollowRequestSchema, packedFollowingSchema } from '@/models/json-schema/following.js'; import { packedGalleryLikeSchema, packedGalleryPostSchema } from '@/models/json-schema/gallery.js'; import { packedHashtagSchema } from '@/models/json-schema/hashtag.js'; @@ -35,10 +35,9 @@ import { packedNotificationSchema } from '@/models/json-schema/notification.js'; import { packedPageLikeSchema, packedPageSchema } from '@/models/json-schema/page.js'; import { packedQueueCountSchema } from '@/models/json-schema/queue.js'; import { packedEmojiDetailedSchema, packedEmojiSimpleSchema } from '@/models/json-schema/emoji.js'; -import { packedFlashSchema } from '@/models/json-schema/flash.js'; import { packedRenoteMutingSchema } from '@/models/json-schema/renote-muting.js'; import { packedRoleSchema } from '@/models/json-schema/role.js'; -import { packedUserListSchema } from '@/models/json-schema/user-list.js'; +import { packedUserListMembershipSchema, packedUserListSchema } from '@/models/json-schema/user-list.js'; import { packedAnnouncementSchema } from '@/models/json-schema/announcement.js'; export const refs = { @@ -51,6 +50,7 @@ export const refs = { User: packedUserSchema, UserList: packedUserListSchema, + UserListMembership: packedUserListMembershipSchema, Announcement: packedAnnouncementSchema, App: packedAppSchema, Note: packedNoteSchema, diff --git a/packages/backend/src/models/json-schema/user-list.ts b/packages/backend/src/models/json-schema/user-list.ts index e257d9984c..9546264552 100644 --- a/packages/backend/src/models/json-schema/user-list.ts +++ b/packages/backend/src/models/json-schema/user-list.ts @@ -37,3 +37,36 @@ export const packedUserListSchema = { }, }, } as const; + +export const packedUserListMembershipSchema = { + type: 'object', + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: 'string', + optional: false, nullable: false, + format: 'date-time', + }, + userId: { + type: 'string', + nullable: false, optional: false, + format: 'id', + example: 'xxxxxxxxxx', + }, + user: { + type: 'object', + optional: false, nullable: false, + ref: 'UserLite', + }, + withReplies: { + type: 'boolean', + nullable: false, + optional: false, + }, + }, +} as const;