-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
147 lines (127 loc) · 3.17 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* Message types for communicating with the daga server.
*
* Duplicated between https://github.com/metadevpro/daga-server/blob/dev/types.ts and
* https://github.com/metadevpro/daga/blob/dev/libs/daga/src/lib/diagram-editor/diagram/collab/message-types.ts
*/
/**
* Stand-in for the DagaModel type on the server.
*/
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface DagaModel {}
/**
* Stand-in for the CollabActionSerialized type on the server.
*/
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface CollabActionSerialized {}
export interface RoomInfo {
locator: string;
ownerId: string;
initialModel: DagaModel;
messages: EsgrimaAddMessage[];
}
export interface UserInfo {
id: string;
username: string;
}
export interface ClientInfo {
key: string;
connection: unknown;
user: UserInfo;
ts: string; // iso-8601
}
// MESSAGE TYPES
export enum EsgrimaMessageType {
ADD = 'ADD',
BYE = 'BYE',
CREATE = 'CREA',
CREATE_ACK = 'CACK',
DELETE = 'DLTE',
ENROLL = 'ENRO',
ENROLL_ACK = 'EACK',
ERROR = 'ERR',
HELLO = 'HELO',
OK = 'OK'
}
export interface ModelChange {
data: CollabActionSerialized;
ts: string;
userId: string;
}
export interface EsgrimaMessage {
/**
* The type of the message.
* @see EsgrimaMessageType
*/
type: EsgrimaMessageType;
/**
* Client ID.
*/
clientId: string;
/**
* User ID.
*/
userId: string;
/**
* Timestamp in an ISO-8601 format.
*/
ts: string;
}
export interface EsgrimaResponseMessage extends EsgrimaMessage {
/**
* The hash of the message that this message is a response to.
*/
responseTo: string;
}
export interface EsgrimaHelloMessage extends EsgrimaMessage {
type: EsgrimaMessageType.HELLO;
token?: string;
/**
* Protocol version.
*/
version: string;
}
export interface EsgrimaByeMessage extends EsgrimaMessage {
type: EsgrimaMessageType.BYE;
}
export interface EsgrimaCreateMessage extends EsgrimaMessage {
type: EsgrimaMessageType.CREATE;
initialModel?: DagaModel;
}
export interface EsgrimaCreateAckMessage extends EsgrimaResponseMessage {
type: EsgrimaMessageType.CREATE_ACK;
locator: string;
}
export interface EsgrimaEnrollMessage extends EsgrimaMessage {
type: EsgrimaMessageType.ENROLL;
locator: string;
}
export interface EsgrimaEnrollAckMessage extends EsgrimaResponseMessage {
type: EsgrimaMessageType.ENROLL_ACK;
locator: string;
ownerId?: string;
initialModel?: DagaModel;
changes: ModelChange[];
userIds: string[];
}
export interface EsgrimaDeleteMessage extends EsgrimaMessage {
type: EsgrimaMessageType.DELETE;
locator: string;
}
export interface EsgrimaAddMessage extends EsgrimaMessage {
type: EsgrimaMessageType.ADD;
locator: string;
payload: CollabActionSerialized;
}
export interface EsgrimaErrorMessage extends EsgrimaResponseMessage {
type: EsgrimaMessageType.ERROR;
locator: string;
status: number;
description: string;
}
export interface EsgrimaOkMessage extends EsgrimaResponseMessage {
type: EsgrimaMessageType.OK;
}
export const hashMessage = (message: EsgrimaMessage): string => {
return `${message.clientId}${message.userId}${message.ts}`;
};