1
0
forked from mirror/misskey
This commit is contained in:
tamaina 2021-09-06 22:47:27 +09:00
parent f4652ec4ac
commit 5db28922d0
7 changed files with 54 additions and 26 deletions

View File

@ -1,7 +1,8 @@
import { EntityRepository, Repository } from 'typeorm'; import { EntityRepository, Repository } from 'typeorm';
import { Emoji } from '@/models/entities/emoji'; import { Emoji } from '@/models/entities/emoji';
import { Resolved } from '@/prelude/types';
export type PackedEmoji = FIXME; export type PackedEmoji = Resolved<ReturnType<EmojiRepository['pack']>>;
@EntityRepository(Emoji) @EntityRepository(Emoji)
export class EmojiRepository extends Repository<Emoji> { export class EmojiRepository extends Repository<Emoji> {

View File

@ -2,8 +2,9 @@ import { User } from '@/models/entities/user';
import { EntityRepository, Repository } from 'typeorm'; import { EntityRepository, Repository } from 'typeorm';
import { Users } from '../../../index'; import { Users } from '../../../index';
import { ReversiGame } from '@/models/entities/games/reversi/game'; import { ReversiGame } from '@/models/entities/games/reversi/game';
import { Resolved } from '@/prelude/types';
export type PackedReversiGame = FIXME; export type PackedReversiGame = Resolved<ReturnType<ReversiGameRepository['pack']>>;
@EntityRepository(ReversiGame) @EntityRepository(ReversiGame)
export class ReversiGameRepository extends Repository<ReversiGame> { export class ReversiGameRepository extends Repository<ReversiGame> {

View File

@ -3,8 +3,9 @@ import { ReversiMatching } from '@/models/entities/games/reversi/matching';
import { Users } from '../../../index'; import { Users } from '../../../index';
import { awaitAll } from '@/prelude/await-all'; import { awaitAll } from '@/prelude/await-all';
import { User } from '@/models/entities/user'; import { User } from '@/models/entities/user';
import { Resolved } from '@/prelude/types';
export type PackedReversiMatching = FIXME; export type PackedReversiMatching = Resolved<ReturnType<ReversiMatchingRepository['pack']>>;
@EntityRepository(ReversiMatching) @EntityRepository(ReversiMatching)
export class ReversiMatchingRepository extends Repository<ReversiMatching> { export class ReversiMatchingRepository extends Repository<ReversiMatching> {

View File

@ -1,10 +1,13 @@
import { EntityRepository, Repository } from 'typeorm'; import { EntityRepository, Repository } from 'typeorm';
import { Signin } from '@/models/entities/signin'; import { Signin } from '@/models/entities/signin';
import { Resolved } from '@/prelude/types';
export type PackedSignin = Resolved<ReturnType<SigninRepository['pack']>>;
@EntityRepository(Signin) @EntityRepository(Signin)
export class SigninRepository extends Repository<Signin> { export class SigninRepository extends Repository<Signin> {
public async pack( public async pack(
src: any, src: Signin,
) { ) {
return src; return src;
} }

1
src/prelude/types.ts Normal file
View File

@ -0,0 +1 @@
export type Resolved<P extends Promise<any>> = P extends Promise<infer R> ? R : never;

View File

@ -23,6 +23,8 @@ import { ReversiGame } from '@/models/entities/games/reversi/game';
import { AbuseUserReport } from '@/models/entities/abuse-user-report'; import { AbuseUserReport } from '@/models/entities/abuse-user-report';
import { PackedEmoji } from '@/models/repositories/emoji'; import { PackedEmoji } from '@/models/repositories/emoji';
import StreamTypes from 'misskey-js/built/streaming.types'; 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 }ユニオンを定義 // 辞書(interface or type)から{ type, body }ユニオンを定義
// https://stackoverflow.com/questions/49311989/can-i-infer-the-type-of-a-value-using-extends-keyof-type // 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 { export interface BroadcastTypes {
emojiAdded: PackedEmoji; emojiAdded: PackedEmoji;
}; }
export interface UserStreamTypes { export interface UserStreamTypes {
terminate: {}; terminate: {};
@ -66,23 +68,42 @@ export interface MainStreamTypes {
followed: PackedUser; followed: PackedUser;
unfollow: PackedUser; unfollow: PackedUser;
meUpdated: PackedUser; meUpdated: PackedUser;
pageEvent: Payload<StreamTypes.Channels['main']['events']['pageEvent']>; pageEvent: {
urlUploadFinished: Payload<StreamTypes.Channels['main']['events']['urlUploadFinished']>; pageId: Page['id'];
readAllNotifications: never; event: string;
unreadNotification: never; var: any;
unreadMention: never; userId: User['id'];
readAllUnreadMentions: never; user: PackedUser;
unreadSpecifiedNote: never; };
readAllUnreadSpecifiedNotes: never; urlUploadFinished: {
readAllMessagingMessages: never; marker?: string | null;
unreadMessagingMessage: never; file: PackedDriveFile;
readAllAntennas: never; };
unreadAntenna: never; readAllNotifications: undefined;
readAllAnnouncements: never; unreadNotification: PackedNotification;
readAllChannels: never; unreadMention: Note['id'];
unreadChannel: never; readAllUnreadMentions: undefined;
myTokenRegenerated: never; 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; reversiInvited: PackedReversiMatching;
signin: PackedSignin;
registryUpdated: {
scope?: string[];
key: string;
value: any | null;
};
driveFileCreated: PackedDriveFile;
readAntenna: Antenna;
} }
export interface DriveStreamTypes { export interface DriveStreamTypes {
@ -207,7 +228,7 @@ export interface AdminStreamTypes {
targetUserId: User['id'], targetUserId: User['id'],
reporterId: User['id'], reporterId: User['id'],
comment: string; comment: string;
} };
} }
//#endregion //#endregion
@ -272,7 +293,7 @@ interface StreamMessages {
admin: { admin: {
name: `adminStream:${User['id']}`; name: `adminStream:${User['id']}`;
spec: EventUnionFromDictionary<AdminStreamTypes>; spec: EventUnionFromDictionary<AdminStreamTypes>;
} };
// and notesStream (specにPackedNoteを突っ込むとなぜかバグる) // and notesStream (specにPackedNoteを突っ込むとなぜかバグる)
} }
//#endregion //#endregion

View File

@ -7,7 +7,7 @@ import { UserGroup } from '@/models/entities/user-group';
import config from '@/config/index'; import config from '@/config/index';
import { Antenna } from '@/models/entities/antenna'; import { Antenna } from '@/models/entities/antenna';
import { Channel } from '@/models/entities/channel'; 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 { class Publisher {
private publish = (channel: Channels, type: string | null, value?: any): void => { 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); this.publish('internal', type, typeof value === 'undefined' ? null : value);
} }
public publishUserEvent = <K extends keyof UserStreamTypes>(userId: User['id'], type: K, value: UserStreamTypes[K]): void => { public publishUserEvent = <K extends keyof UserStreamTypes>(userId: User['id'], type: K, value?: UserStreamTypes[K]): void => {
this.publish(`user:${userId}`, type, typeof value === 'undefined' ? null : value); 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); this.publish('broadcast', type, typeof value === 'undefined' ? null : value);
} }
public publishMainStream = (userId: User['id'], type: string, value?: any): void => { public publishMainStream = <K extends keyof MainStreamTypes>(userId: User['id'], type: K, value?: MainStreamTypes[K]): void => {
this.publish(`mainStream:${userId}`, type, typeof value === 'undefined' ? null : value); this.publish(`mainStream:${userId}`, type, typeof value === 'undefined' ? null : value);
} }