From 3afdfe848b1e5f442cd86985adce652ec3c98efb Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 12 Sep 2021 21:11:06 +0900 Subject: [PATCH 1/4] 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; From ce0f3741b9eb7294d67a671b56d80a8ae266a474 Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 12 Sep 2021 21:39:02 +0900 Subject: [PATCH 2/4] add reversiGame --- src/models/repositories/games/reversi/game.ts | 153 +++++++++++++++++- 1 file changed, 147 insertions(+), 6 deletions(-) diff --git a/src/models/repositories/games/reversi/game.ts b/src/models/repositories/games/reversi/game.ts index 10433bf58f..121a3cad74 100644 --- a/src/models/repositories/games/reversi/game.ts +++ b/src/models/repositories/games/reversi/game.ts @@ -2,9 +2,9 @@ import { User } from '@/models/entities/user'; import { EntityRepository, Repository } from 'typeorm'; import { Users } from '../../../index'; import { ReversiGame } from '@/models/entities/games/reversi/game'; -import { Resolved } from '@/prelude/types'; +import { SchemaType } from '@/misc/schema'; -export type PackedReversiGame = Resolved>; +export type PackedReversiGame = SchemaType; @EntityRepository(ReversiGame) export class ReversiGameRepository extends Repository { @@ -14,7 +14,7 @@ export class ReversiGameRepository extends Repository { options?: { detail?: boolean } - ) { + ): Promise { const opts = Object.assign({ detail: true }, options); @@ -23,8 +23,8 @@ export class ReversiGameRepository extends Repository { return { id: game.id, - createdAt: game.createdAt, - startedAt: game.startedAt, + createdAt: game.createdAt.toISOString(), + startedAt: game.startedAt && game.startedAt.toISOString(), isStarted: game.isStarted, isEnded: game.isEnded, form1: game.form1, @@ -44,9 +44,150 @@ export class ReversiGameRepository extends Repository { canPutEverywhere: game.canPutEverywhere, loopedBoard: game.loopedBoard, ...(opts.detail ? { - logs: game.logs, + logs: game.logs.map(log => ({ + at: log.at.toISOString(), + color: log.color, + pos: log.pos + })), map: game.map, } : {}) }; } } + +export const packedReversiGameSchema = { + 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', + }, + createdAt: { + type: 'string' as const, + optional: false as const, nullable: false as const, + format: 'date-time', + }, + startedAt: { + type: 'string' as const, + optional: false as const, nullable: true as const, + format: 'date-time', + }, + isStarted: { + type: 'boolean' as const, + optional: false as const, nullable: false as const, + }, + isEnded: { + type: 'boolean' as const, + optional: false as const, nullable: false as const, + }, + form1: { + type: 'any' as const, + optional: false as const, nullable: true as const, + }, + form2: { + type: 'any' as const, + optional: false as const, nullable: true as const, + }, + user1Accepted: { + type: 'boolean' as const, + optional: false as const, nullable: false as const, + }, + user2Accepted: { + type: 'boolean' as const, + optional: false as const, nullable: false as const, + }, + user1Id: { + type: 'string' as const, + optional: false as const, nullable: false as const, + format: 'id', + example: 'xxxxxxxxxx', + }, + user2Id: { + type: 'string' as const, + optional: false as const, nullable: false as const, + format: 'id', + example: 'xxxxxxxxxx', + }, + user1: { + type: 'object' as const, + optional: false as const, nullable: false as const, + ref: 'User' as const, + }, + user2: { + type: 'object' as const, + optional: false as const, nullable: false as const, + ref: 'User' as const, + }, + winnerId: { + type: 'string' as const, + optional: false as const, nullable: true as const, + format: 'id', + example: 'xxxxxxxxxx', + }, + winner: { + type: 'object' as const, + optional: false as const, nullable: true as const, + ref: 'User' as const, + }, + surrendered: { + type: 'string' as const, + optional: false as const, nullable: true as const, + format: 'id', + example: 'xxxxxxxxxx', + }, + black: { + type: 'number' as const, + optional: false as const, nullable: true as const, + }, + bw: { + type: 'string' as const, + optional: false as const, nullable: false as const, + }, + isLlotheo: { + type: 'boolean' as const, + optional: false as const, nullable: false as const, + }, + canPutEverywhere: { + type: 'boolean' as const, + optional: false as const, nullable: false as const, + }, + loopedBoard: { + type: 'boolean' as const, + optional: false as const, nullable: false as const, + }, + logs: { + type: 'array' as const, + optional: true as const, nullable: false as const, + items: { + type: 'object' as const, + optional: true as const, nullable: false as const, + properties: { + at: { + type: 'string' as const, + optional: false as const, nullable: false as const, + format: 'date-time', + }, + color: { + type: 'boolean' as const, + optional: false as const, nullable: false as const, + }, + pos: { + type: 'number' as const, + optional: false as const, nullable: false as const, + }, + } + } + }, + map: { + type: 'array' as const, + optional: true as const, nullable: false as const, + items: { + type: 'string' as const, + optional: false as const, nullable: false as const, + } + } + } +}; From ef98e4ab4f1c14b51af139f97431b50ea55d953e Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 12 Sep 2021 21:44:32 +0900 Subject: [PATCH 3/4] add reversiMatching --- .../repositories/games/reversi/matching.ts | 48 +++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/models/repositories/games/reversi/matching.ts b/src/models/repositories/games/reversi/matching.ts index 2696f1f8ea..0cf3b9fd35 100644 --- a/src/models/repositories/games/reversi/matching.ts +++ b/src/models/repositories/games/reversi/matching.ts @@ -3,21 +3,21 @@ import { ReversiMatching } from '@/models/entities/games/reversi/matching'; import { Users } from '../../../index'; import { awaitAll } from '@/prelude/await-all'; import { User } from '@/models/entities/user'; -import { Resolved } from '@/prelude/types'; +import { SchemaType } from '@/misc/schema'; -export type PackedReversiMatching = Resolved>; +export type PackedReversiMatching = SchemaType; @EntityRepository(ReversiMatching) export class ReversiMatchingRepository extends Repository { public async pack( src: ReversiMatching['id'] | ReversiMatching, me: { id: User['id'] } - ) { + ): Promise { const matching = typeof src === 'object' ? src : await this.findOneOrFail(src); return await awaitAll({ id: matching.id, - createdAt: matching.createdAt, + createdAt: matching.createdAt.toISOString(), parentId: matching.parentId, parent: Users.pack(matching.parentId, me, { detail: true @@ -29,3 +29,43 @@ export class ReversiMatchingRepository extends Repository { }); } } + +export const packedReversiMatchingSchema = { + 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', + }, + createdAt: { + type: 'string' as const, + optional: false as const, nullable: false as const, + format: 'date-time', + }, + parentId: { + type: 'string' as const, + optional: false as const, nullable: false as const, + format: 'id', + example: 'xxxxxxxxxx', + }, + parent: { + type: 'object' as const, + optional: false as const, nullable: true as const, + ref: 'User' as const, + }, + childId: { + type: 'string' as const, + optional: false as const, nullable: false as const, + format: 'id', + example: 'xxxxxxxxxx', + }, + child: { + type: 'object' as const, + optional: false as const, nullable: false as const, + ref: 'User' as const, + }, + } +}; From ee3457cb094cbec4b43261bae9400b4461250856 Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 12 Sep 2021 21:46:26 +0900 Subject: [PATCH 4/4] remove signin schema (use Signin entity) --- src/models/repositories/signin.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/models/repositories/signin.ts b/src/models/repositories/signin.ts index 8038760742..9942d2d962 100644 --- a/src/models/repositories/signin.ts +++ b/src/models/repositories/signin.ts @@ -1,8 +1,5 @@ import { EntityRepository, Repository } from 'typeorm'; import { Signin } from '@/models/entities/signin'; -import { Resolved } from '@/prelude/types'; - -export type PackedSignin = Resolved>; @EntityRepository(Signin) export class SigninRepository extends Repository {