(core) Converting server-side Comm.js to typescript

Summary:
- Add app/common/CommTypes.ts to define types shared by client and server.
- Include @types/ws npm package

Test Plan: Intended to have no changes in behavior

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3467
This commit is contained in:
Dmitry S
2022-06-04 00:12:30 -04:00
parent 519f1be93a
commit 4f1cb53b29
23 changed files with 655 additions and 716 deletions

View File

@@ -3,6 +3,7 @@
* open, and what FD they are using.
*/
import {CommDocEventType} from 'app/common/CommTypes';
import {arrayRemove} from 'app/common/gutil';
import {ActiveDoc} from 'app/server/lib/ActiveDoc';
import {Authorizer} from 'app/server/lib/Authorizer';
@@ -81,7 +82,7 @@ export class DocClients {
* @param {Object} messageData: The data for this type of message.
* @param {Object} filterMessage: Optional callback to filter message per client.
*/
public async broadcastDocMessage(client: Client|null, type: string, messageData: any,
public async broadcastDocMessage(client: Client|null, type: CommDocEventType, messageData: any,
filterMessage?: (docSession: OptDocSession,
messageData: any) => Promise<any>): Promise<void> {
const send = (curr: DocSession) => this._send(curr, client, type, messageData, filterMessage);
@@ -102,7 +103,7 @@ export class DocClients {
/**
* Send a message to a single client. See broadcastDocMessage for parameters.
*/
private async _send(target: DocSession, client: Client|null, type: string, messageData: any,
private async _send(target: DocSession, client: Client|null, type: CommDocEventType, messageData: any,
filterMessage?: (docSession: OptDocSession,
messageData: any) => Promise<any>): Promise<void> {
const fromSelf = (target.client === client);