Skip to content

Commit

Permalink
fix(build): Add typing for SSE channel (#4196)
Browse files Browse the repository at this point in the history
📘 Add typing for SSE channel
  • Loading branch information
ivov authored Sep 26, 2022
1 parent 3db53a1 commit eaf13cd
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/cli/src/Push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@ interface SSEChannelOptions {
};
}

namespace SSE {
export type Channel = {
on(event: string, handler: (channel: string, res: express.Response) => void): void;
removeClient: (res: express.Response) => void;
addClient: (req: express.Request, res: express.Response) => void;
send: (msg: string, clients?: express.Response[]) => void;
};
}

export class Push {
private channel: sseChannel;
private channel: SSE.Channel;

private connections: {
[key: string]: express.Response;
Expand All @@ -28,9 +37,8 @@ export class Push {
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
this.channel = new sseChannel(options);
this.channel = new sseChannel(options) as SSE.Channel;

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
this.channel.on('disconnect', (channel: string, res: express.Response) => {
if (res.req !== undefined) {
Logger.debug(`Remove editor-UI session`, { sessionId: res.req.query.sessionId });
Expand All @@ -47,7 +55,6 @@ export class Push {
* @param {express.Response} res The response
* @memberof Push
*/
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
add(sessionId: string, req: express.Request, res: express.Response) {
Logger.debug(`Add editor-UI session`, { sessionId });

Expand All @@ -71,7 +78,7 @@ export class Push {
* @memberof Push
*/

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
send(type: IPushDataType, data: any, sessionId?: string) {
if (sessionId !== undefined && this.connections[sessionId] === undefined) {
Logger.error(`The session "${sessionId}" is not registered.`, { sessionId });
Expand Down

0 comments on commit eaf13cd

Please sign in to comment.