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 { Emoji } from '@/models/entities/emoji';
import { Resolved } from '@/prelude/types';
export type PackedEmoji = FIXME;
export type PackedEmoji = Resolved<ReturnType<EmojiRepository['pack']>>;
@EntityRepository(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 { Users } from '../../../index';
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)
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 { awaitAll } from '@/prelude/await-all';
import { User } from '@/models/entities/user';
import { Resolved } from '@/prelude/types';
export type PackedReversiMatching = FIXME;
export type PackedReversiMatching = Resolved<ReturnType<ReversiMatchingRepository['pack']>>;
@EntityRepository(ReversiMatching)
export class ReversiMatchingRepository extends Repository<ReversiMatching> {

View File

@ -1,10 +1,13 @@
import { EntityRepository, Repository } from 'typeorm';
import { Signin } from '@/models/entities/signin';
import { Resolved } from '@/prelude/types';
export type PackedSignin = Resolved<ReturnType<SigninRepository['pack']>>;
@EntityRepository(Signin)
export class SigninRepository extends Repository<Signin> {
public async pack(
src: any,
src: Signin,
) {
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 { 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<StreamTypes.Channels['main']['events']['pageEvent']>;
urlUploadFinished: Payload<StreamTypes.Channels['main']['events']['urlUploadFinished']>;
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<AdminStreamTypes>;
}
};
// and notesStream (specにPackedNoteを突っ込むとなぜかバグる)
}
//#endregion

View File

@ -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 = <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);
}
@ -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 = <K extends keyof MainStreamTypes>(userId: User['id'], type: K, value?: MainStreamTypes[K]): void => {
this.publish(`mainStream:${userId}`, type, typeof value === 'undefined' ? null : value);
}