From 287f59523967222b9fbdbc1d83cdd687c603bf2f Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 14 Jan 2022 01:33:42 +0900 Subject: [PATCH] Resolve #38 --- CHANGELOG.md | 3 + etc/misskey-js.api.md | 146 ++++++++++++++++++++++++++++++++++++++++-- src/index.ts | 5 +- src/streaming.ts | 2 +- 4 files changed, 150 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bac439a040..c188a2b556 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 0.0.13 +- expose ChannelConnection and Channels types + # 0.0.12 - fix a bug that cannot connect to streaming diff --git a/etc/misskey-js.api.md b/etc/misskey-js.api.md index e606c9a93a..1a462ba4e9 100644 --- a/etc/misskey-js.api.md +++ b/etc/misskey-js.api.md @@ -113,6 +113,146 @@ type Channel = { id: ID; }; +// Warning: (ae-forgotten-export) The symbol "AnyOf" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +export abstract class ChannelConnection = any> extends EventEmitter { + constructor(stream: Stream, channel: string, name?: string); + // (undocumented) + channel: string; + // (undocumented) + abstract dispose(): void; + // (undocumented) + abstract id: string; + // (undocumented) + inCount: number; + // (undocumented) + name?: string; + // (undocumented) + outCount: number; + // (undocumented) + send(type: T, body: Channel['receives'][T]): void; + // (undocumented) + protected stream: Stream; +} + +// @public (undocumented) +export type Channels = { + main: { + params: null; + events: { + notification: (payload: Notification_2) => void; + mention: (payload: Note) => void; + reply: (payload: Note) => void; + renote: (payload: Note) => void; + follow: (payload: User) => void; + followed: (payload: User) => void; + unfollow: (payload: User) => void; + meUpdated: (payload: MeDetailed) => void; + pageEvent: (payload: PageEvent) => void; + urlUploadFinished: (payload: { + marker: string; + file: DriveFile; + }) => void; + readAllNotifications: () => void; + unreadNotification: (payload: Notification_2) => void; + unreadMention: (payload: Note['id']) => void; + readAllUnreadMentions: () => void; + unreadSpecifiedNote: (payload: Note['id']) => void; + readAllUnreadSpecifiedNotes: () => void; + readAllMessagingMessages: () => void; + messagingMessage: (payload: MessagingMessage) => void; + unreadMessagingMessage: (payload: MessagingMessage) => void; + readAllAntennas: () => void; + unreadAntenna: (payload: Antenna) => void; + readAllAnnouncements: () => void; + readAllChannels: () => void; + unreadChannel: (payload: Note['id']) => void; + myTokenRegenerated: () => void; + reversiNoInvites: () => void; + reversiInvited: (payload: FIXME) => void; + signin: (payload: FIXME) => void; + registryUpdated: (payload: { + scope?: string[]; + key: string; + value: any | null; + }) => void; + driveFileCreated: (payload: DriveFile) => void; + readAntenna: (payload: Antenna) => void; + }; + receives: null; + }; + homeTimeline: { + params: null; + events: { + note: (payload: Note) => void; + }; + receives: null; + }; + localTimeline: { + params: null; + events: { + note: (payload: Note) => void; + }; + receives: null; + }; + hybridTimeline: { + params: null; + events: { + note: (payload: Note) => void; + }; + receives: null; + }; + globalTimeline: { + params: null; + events: { + note: (payload: Note) => void; + }; + receives: null; + }; + messaging: { + params: { + otherparty?: User['id'] | null; + group?: UserGroup['id'] | null; + }; + events: { + message: (payload: MessagingMessage) => void; + deleted: (payload: MessagingMessage['id']) => void; + read: (payload: MessagingMessage['id'][]) => void; + typers: (payload: User[]) => void; + }; + receives: { + read: { + id: MessagingMessage['id']; + }; + }; + }; + serverStats: { + params: null; + events: { + stats: (payload: FIXME) => void; + }; + receives: { + requestLog: { + id: string | number; + length: number; + }; + }; + }; + queueStats: { + params: null; + events: { + stats: (payload: FIXME) => void; + }; + receives: { + requestLog: { + id: string | number; + length: number; + }; + }; + }; +}; + // @public (undocumented) type Clip = TODO_2; @@ -2422,11 +2562,8 @@ export class Stream extends EventEmitter { send(typeOrPayload: any, payload?: any): void; // (undocumented) state: 'initializing' | 'reconnecting' | 'connected'; - // Warning: (ae-forgotten-export) The symbol "Channels" needs to be exported by the entry point index.d.ts - // Warning: (ae-forgotten-export) The symbol "Connection" needs to be exported by the entry point index.d.ts - // // (undocumented) - useChannel(channel: C, params?: Channels[C]['params'], name?: string): Connection; + useChannel(channel: C, params?: Channels[C]['params'], name?: string): ChannelConnection; } // @public (undocumented) @@ -2519,6 +2656,7 @@ type UserSorting = '+follower' | '-follower' | '+createdAt' | '-createdAt' | '+u // src/api.types.ts:16:32 - (ae-forgotten-export) The symbol "TODO" needs to be exported by the entry point index.d.ts // src/api.types.ts:18:25 - (ae-forgotten-export) The symbol "NoParams" needs to be exported by the entry point index.d.ts // src/api.types.ts:595:18 - (ae-forgotten-export) The symbol "ShowUserReq" needs to be exported by the entry point index.d.ts +// src/streaming.types.ts:35:4 - (ae-forgotten-export) The symbol "FIXME" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/src/index.ts b/src/index.ts index 60748ebe0b..f431d65cc7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,14 @@ import { Endpoints } from './api.types'; -import Stream from './streaming'; +import Stream, { Connection } from './streaming'; +import { Channels } from './streaming.types'; import { Acct } from './acct'; import * as consts from './consts'; export { Endpoints, Stream, + Connection as ChannelConnection, + Channels, Acct, }; diff --git a/src/streaming.ts b/src/streaming.ts index 0f41bddd40..c354a758f4 100644 --- a/src/streaming.ts +++ b/src/streaming.ts @@ -256,7 +256,7 @@ class Pool { } } -abstract class Connection = any> extends EventEmitter { +export abstract class Connection = any> extends EventEmitter { public channel: string; protected stream: Stream; public abstract id: string;