misskey-js側にinterfaceを置いて型エラーを解消

This commit is contained in:
kakkokari-gtyih
2024-06-24 18:26:03 +09:00
parent 584e80dedd
commit 313ebcde43
4 changed files with 47 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
import { type Endpoints } from './api.types.js';
import Stream, { Connection } from './streaming.js';
import { type StreamEvents } from './streaming.js';
import type { StreamEvents, IStream, IChannelConnection } from './streaming.js';
import { type Channels } from './streaming.types.js';
import { type Acct } from './acct.js';
import * as consts from './consts.js';
@@ -10,6 +10,8 @@ export type {
Channels,
Acct,
StreamEvents,
IStream,
IChannelConnection,
};
export {

View File

@@ -22,10 +22,26 @@ export type StreamEvents = {
_disconnected_: void;
} & BroadcastEvents;
export interface IStream extends EventEmitter<StreamEvents> {
state: 'initializing' | 'reconnecting' | 'connected';
useChannel<C extends keyof Channels>(channel: C, params?: Channels[C]['params'], name?: string): IChannelConnection<Channels[C]>;
removeSharedConnection(connection: SharedConnection): void;
removeSharedConnectionPool(pool: Pool): void;
disconnectToChannel(connection: NonSharedConnection): void;
send(typeOrPayload: string): void;
send(typeOrPayload: string, payload: any): void;
send(typeOrPayload: Record<string, any> | any[]): void;
send(typeOrPayload: string | Record<string, any> | any[], payload?: any): void;
ping(): void;
heartbeat(): void;
close(): void;
};
/**
* Misskey stream connection
*/
export default class Stream extends EventEmitter<StreamEvents> {
export default class Stream extends EventEmitter<StreamEvents> implements IStream {
private stream: _ReconnectingWebsocket.default;
public state: 'initializing' | 'reconnecting' | 'connected' = 'initializing';
private sharedConnectionPools: Pool[] = [];
@@ -275,7 +291,18 @@ class Pool {
}
}
export abstract class Connection<Channel extends AnyOf<Channels> = any> extends EventEmitter<Channel['events']> {
export interface IChannelConnection<Channel extends AnyOf<Channels> = any> extends EventEmitter<Channel['events']> {
id: string;
name?: string;
inCount: number;
outCount: number;
channel: string;
send<T extends keyof Channel['receives']>(type: T, body: Channel['receives'][T]): void;
dispose(): void;
}
export abstract class Connection<Channel extends AnyOf<Channels> = any> extends EventEmitter<Channel['events']> implements IChannelConnection<Channel> {
public channel: string;
protected stream: Stream;
public abstract id: string;