From 5db28922d04c9496dc6482421eeaeeeba6f97d57 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 6 Sep 2021 22:47:27 +0900 Subject: [PATCH] wip --- src/models/repositories/emoji.ts | 3 +- src/models/repositories/games/reversi/game.ts | 3 +- .../repositories/games/reversi/matching.ts | 3 +- src/models/repositories/signin.ts | 5 +- src/prelude/types.ts | 1 + src/server/api/stream/types.ts | 59 +++++++++++++------ src/services/stream.ts | 6 +- 7 files changed, 54 insertions(+), 26 deletions(-) create mode 100644 src/prelude/types.ts diff --git a/src/models/repositories/emoji.ts b/src/models/repositories/emoji.ts index 1bbe6b8215..2dc5f5282a 100644 --- a/src/models/repositories/emoji.ts +++ b/src/models/repositories/emoji.ts @@ -1,7 +1,8 @@ import { EntityRepository, Repository } from 'typeorm'; import { Emoji } from '@/models/entities/emoji'; +import { Resolved } from '@/prelude/types'; -export type PackedEmoji = FIXME; +export type PackedEmoji = Resolved>; @EntityRepository(Emoji) export class EmojiRepository extends Repository { diff --git a/src/models/repositories/games/reversi/game.ts b/src/models/repositories/games/reversi/game.ts index eb2561be91..10433bf58f 100644 --- a/src/models/repositories/games/reversi/game.ts +++ b/src/models/repositories/games/reversi/game.ts @@ -2,8 +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'; -export type PackedReversiGame = FIXME; +export type PackedReversiGame = Resolved>; @EntityRepository(ReversiGame) export class ReversiGameRepository extends Repository { diff --git a/src/models/repositories/games/reversi/matching.ts b/src/models/repositories/games/reversi/matching.ts index 91615091ac..2696f1f8ea 100644 --- a/src/models/repositories/games/reversi/matching.ts +++ b/src/models/repositories/games/reversi/matching.ts @@ -3,8 +3,9 @@ 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'; -export type PackedReversiMatching = FIXME; +export type PackedReversiMatching = Resolved>; @EntityRepository(ReversiMatching) export class ReversiMatchingRepository extends Repository { diff --git a/src/models/repositories/signin.ts b/src/models/repositories/signin.ts index 9942d2d962..79d23241a7 100644 --- a/src/models/repositories/signin.ts +++ b/src/models/repositories/signin.ts @@ -1,10 +1,13 @@ 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 { public async pack( - src: any, + src: Signin, ) { return src; } diff --git a/src/prelude/types.ts b/src/prelude/types.ts new file mode 100644 index 0000000000..d004d0ff31 --- /dev/null +++ b/src/prelude/types.ts @@ -0,0 +1 @@ +export type Resolved

> = P extends Promise ? R : never; diff --git a/src/server/api/stream/types.ts b/src/server/api/stream/types.ts index 7d2e918af6..db947bd1f4 100644 --- a/src/server/api/stream/types.ts +++ b/src/server/api/stream/types.ts @@ -23,6 +23,8 @@ import { ReversiGame } from '@/models/entities/games/reversi/game'; import { AbuseUserReport } from '@/models/entities/abuse-user-report'; import { PackedEmoji } from '@/models/repositories/emoji'; import StreamTypes from 'misskey-js/built/streaming.types'; +import { PackedSignin } from '@/models/repositories/signin'; +import { Page } from '@/models/entities/page'; // 辞書(interface or type)から{ type, body }ユニオンを定義 // https://stackoverflow.com/questions/49311989/can-i-infer-the-type-of-a-value-using-extends-keyof-type @@ -43,7 +45,7 @@ export interface InternalStreamTypes { export interface BroadcastTypes { emojiAdded: PackedEmoji; -}; +} export interface UserStreamTypes { terminate: {}; @@ -66,23 +68,42 @@ export interface MainStreamTypes { followed: PackedUser; unfollow: PackedUser; meUpdated: PackedUser; - pageEvent: Payload; - urlUploadFinished: Payload; - readAllNotifications: never; - unreadNotification: never; - unreadMention: never; - readAllUnreadMentions: never; - unreadSpecifiedNote: never; - readAllUnreadSpecifiedNotes: never; - readAllMessagingMessages: never; - unreadMessagingMessage: never; - readAllAntennas: never; - unreadAntenna: never; - readAllAnnouncements: never; - readAllChannels: never; - unreadChannel: never; - myTokenRegenerated: never; + pageEvent: { + pageId: Page['id']; + event: string; + var: any; + userId: User['id']; + user: PackedUser; + }; + urlUploadFinished: { + marker?: string | null; + file: PackedDriveFile; + }; + readAllNotifications: undefined; + unreadNotification: PackedNotification; + unreadMention: Note['id']; + readAllUnreadMentions: undefined; + unreadSpecifiedNote: Note['id']; + readAllUnreadSpecifiedNotes: undefined; + readAllMessagingMessages: undefined; + messagingMessage: PackedMessagingMessage; + unreadMessagingMessage: PackedMessagingMessage; + readAllAntennas: undefined; + unreadAntenna: Antenna; + readAllAnnouncements: undefined; + readAllChannels: undefined; + unreadChannel: Note['id']; + myTokenRegenerated: undefined; + reversiNoInvites: undefined; reversiInvited: PackedReversiMatching; + signin: PackedSignin; + registryUpdated: { + scope?: string[]; + key: string; + value: any | null; + }; + driveFileCreated: PackedDriveFile; + readAntenna: Antenna; } export interface DriveStreamTypes { @@ -207,7 +228,7 @@ export interface AdminStreamTypes { targetUserId: User['id'], reporterId: User['id'], comment: string; - } + }; } //#endregion @@ -272,7 +293,7 @@ interface StreamMessages { admin: { name: `adminStream:${User['id']}`; spec: EventUnionFromDictionary; - } + }; // and notesStream (specにPackedNoteを突っ込むとなぜかバグる) } //#endregion diff --git a/src/services/stream.ts b/src/services/stream.ts index 20c019f57d..3b0c90d75c 100644 --- a/src/services/stream.ts +++ b/src/services/stream.ts @@ -7,7 +7,7 @@ import { UserGroup } from '@/models/entities/user-group'; import config from '@/config/index'; import { Antenna } from '@/models/entities/antenna'; import { Channel } from '@/models/entities/channel'; -import { BroadcastTypes, Channels, InternalStreamTypes, UserStreamTypes } from '@/server/api/stream/types'; +import { BroadcastTypes, Channels, InternalStreamTypes, MainStreamTypes, UserStreamTypes } from '@/server/api/stream/types'; class Publisher { private publish = (channel: Channels, type: string | null, value?: any): void => { @@ -25,7 +25,7 @@ class Publisher { this.publish('internal', type, typeof value === 'undefined' ? null : value); } - public publishUserEvent = (userId: User['id'], type: K, value: UserStreamTypes[K]): void => { + public publishUserEvent = (userId: User['id'], type: K, value?: UserStreamTypes[K]): void => { this.publish(`user:${userId}`, type, typeof value === 'undefined' ? null : value); } @@ -33,7 +33,7 @@ class Publisher { this.publish('broadcast', type, typeof value === 'undefined' ? null : value); } - public publishMainStream = (userId: User['id'], type: string, value?: any): void => { + public publishMainStream = (userId: User['id'], type: K, value?: MainStreamTypes[K]): void => { this.publish(`mainStream:${userId}`, type, typeof value === 'undefined' ? null : value); }