From 3afdfe848b1e5f442cd86985adce652ec3c98efb Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 12 Sep 2021 21:11:06 +0900 Subject: [PATCH] add emoji schema --- src/models/repositories/emoji.ts | 44 +++++++++++++++++++++++++++++--- src/prelude/types.ts | 1 - 2 files changed, 41 insertions(+), 4 deletions(-) delete mode 100644 src/prelude/types.ts diff --git a/src/models/repositories/emoji.ts b/src/models/repositories/emoji.ts index 2dc5f5282a..24f03574fe 100644 --- a/src/models/repositories/emoji.ts +++ b/src/models/repositories/emoji.ts @@ -1,14 +1,14 @@ import { EntityRepository, Repository } from 'typeorm'; import { Emoji } from '@/models/entities/emoji'; -import { Resolved } from '@/prelude/types'; +import { SchemaType } from '@/misc/schema'; -export type PackedEmoji = Resolved>; +export type PackedEmoji = SchemaType; @EntityRepository(Emoji) export class EmojiRepository extends Repository { public async pack( src: Emoji['id'] | Emoji, - ) { + ): Promise { const emoji = typeof src === 'object' ? src : await this.findOneOrFail(src); return { @@ -27,3 +27,41 @@ export class EmojiRepository extends Repository { return Promise.all(emojis.map(x => this.pack(x))); } } + +export const packedEmojiSchema = { + type: 'object' as const, + optional: false as const, nullable: false as const, + properties: { + id: { + type: 'string' as const, + optional: false as const, nullable: false as const, + format: 'id', + example: 'xxxxxxxxxx', + }, + aliases: { + type: 'array' as const, + optional: false as const, nullable: false as const, + items: { + type: 'string' as const, + optional: false as const, nullable: false as const, + format: 'id', + }, + }, + name: { + type: 'string' as const, + optional: false as const, nullable: false as const, + }, + category: { + type: 'string' as const, + optional: false as const, nullable: true as const, + }, + host: { + type: 'string' as const, + optional: false as const, nullable: true as const, + }, + url: { + type: 'string' as const, + optional: false as const, nullable: false as const, + }, + } +}; diff --git a/src/prelude/types.ts b/src/prelude/types.ts deleted file mode 100644 index b8c49f9292..0000000000 --- a/src/prelude/types.ts +++ /dev/null @@ -1 +0,0 @@ -export type Resolved

= P extends PromiseLike ? Resolved : never;