diff --git a/src/server/api/stream/types.ts b/src/server/api/stream/types.ts index 3803e6dcea..e35a810ac7 100644 --- a/src/server/api/stream/types.ts +++ b/src/server/api/stream/types.ts @@ -32,20 +32,12 @@ type EventUnionFromMkJSTypes< > = U[keyof U]; //#region Stream type-body definitions - -// internal export interface InternalStreamTypes { antennaCreated: Antenna; antennaDeleted: Antenna; antennaUpdated: Antenna; } -export type InternalStreams = EventUnionFromDictionary; -// broadcast -export type BroadcastStreams = EventUnionFromMkJSTypes; - -// user -export type UserEventName = `user:${User['id']}`; export interface UserStreamTypes { terminate: {}; followChannel: Channel; @@ -57,10 +49,7 @@ export interface UserStreamTypes { unfollow: PackedUser; userAdded: PackedUser; } -export type UserStreams = EventUnionFromDictionary; -// main -export type mainStreamName = `mainStream:${User['id']}`; export interface MainStreamTypes { notification: PackedNotification; mention: PackedNote; @@ -87,10 +76,7 @@ export interface MainStreamTypes { unreadChannel: never; myTokenRegenerated: never; } -export type mainStreams = EventUnionFromDictionary; -// drive -export type driveStreamName = `driveStream:${User['id']}`; export interface DriveStreamTypes { fileCreated: PackedDriveFile; fileDeleted: DriveFile['id']; @@ -99,10 +85,7 @@ export interface DriveStreamTypes { folderDeleted: DriveFolder['id']; folderUpdated: PackedDriveFolder; } -export type driveStreams= EventUnionFromDictionary; -// note -export type noteStreamName = `noteStream:${Note['id']}`; export interface NoteStreamTypes { pollVoted: { id: Note['id']; @@ -133,22 +116,40 @@ export interface NoteStreamTypes { } }; } -export type noteStreams = EventUnionFromDictionary; + +//#endregion +//#region 名前とメッセージのペアを中間生成 +interface StreamMessages { + internal: { + name: 'internal'; + spec: EventUnionFromDictionary; + }; + broadcast: { + name: 'bloadcast'; + spec: EventUnionFromMkJSTypes; + }; + user: { + name: `user:${User['id']}`; + spec: EventUnionFromDictionary; + }; + main: { + name: `mainStream:${User['id']}`; + spec: EventUnionFromDictionary; + }; + drive: { + name: `driveStream:${User['id']}`; + spec: EventUnionFromDictionary; + }; + note: { + name: `noteStream:${Note['id']}`; + spec: EventUnionFromDictionary; + } +} //#endregion -//#region API event definitions -interface StreamEvents { - 'broadcast': (e: BroadcastStreams) => void; - 'internal': (e: InternalStreams) => void; -} - -interface AuthenticatedStreamEvents { - [key: UserEventName]: (e: UserStreams) => void; - [key: mainStreamName]: (e: mainStreams) => void; - [key: driveStreamName]: (e: driveStreams) => void; - [key: noteStreamName]: (e: noteStreams) => void; -} - -export type StreamEventEmitter = Emitter; -//#endregion +// API event definitions +type Events = { + [x in S[T]['name']]: (e: S[T]['spec']) => void +}; +export type StreamEventEmitter = Emitter>;