aboutsummaryrefslogtreecommitdiffstats
path: root/language-web/src/main/js/editor/xtextMessages.ts
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2021-10-25 00:29:37 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2021-10-31 19:26:11 +0100
commitdcbfeece5e559b60a615f0aa9b933b202d34bf8b (patch)
treeafdacff7492284f5f8cc147c4b84e4ba5db259b3 /language-web/src/main/js/editor/xtextMessages.ts
parenttest(web): more websocket integration tests (diff)
downloadrefinery-dcbfeece5e559b60a615f0aa9b933b202d34bf8b.tar.gz
refinery-dcbfeece5e559b60a615f0aa9b933b202d34bf8b.tar.zst
refinery-dcbfeece5e559b60a615f0aa9b933b202d34bf8b.zip
feat(web): add xtext websocket client
Diffstat (limited to 'language-web/src/main/js/editor/xtextMessages.ts')
-rw-r--r--language-web/src/main/js/editor/xtextMessages.ts55
1 files changed, 55 insertions, 0 deletions
diff --git a/language-web/src/main/js/editor/xtextMessages.ts b/language-web/src/main/js/editor/xtextMessages.ts
new file mode 100644
index 00000000..d3cb9425
--- /dev/null
+++ b/language-web/src/main/js/editor/xtextMessages.ts
@@ -0,0 +1,55 @@
1export interface IXtextWebRequest {
2 id: string;
3
4 request: unknown;
5}
6
7export interface IXtextWebOkResponse {
8 id: string;
9
10 response: unknown;
11}
12
13export function isOkResponse(response: unknown): response is IXtextWebOkResponse {
14 const okResponse = response as IXtextWebOkResponse;
15 return typeof okResponse.id === 'string'
16 && typeof okResponse.response !== 'undefined';
17}
18
19export const VALID_XTEXT_WEB_ERROR_KINDS = ['request', 'server'] as const;
20
21export type XtextWebErrorKind = typeof VALID_XTEXT_WEB_ERROR_KINDS[number];
22
23export interface IXtextWebErrorResponse {
24 id: string;
25
26 error: XtextWebErrorKind;
27
28 message: string;
29}
30
31export function isErrorResponse(response: unknown): response is IXtextWebErrorResponse {
32 const errorResponse = response as IXtextWebErrorResponse;
33 return typeof errorResponse.id === 'string'
34 && typeof errorResponse.error === 'string'
35 && VALID_XTEXT_WEB_ERROR_KINDS.includes(errorResponse.error)
36 && typeof errorResponse.message === 'string';
37}
38
39export interface IXtextWebPushMessage {
40 resource: string;
41
42 stateId: string;
43
44 service: string;
45
46 push: unknown;
47}
48
49export function isPushMessage(response: unknown): response is IXtextWebPushMessage {
50 const pushMessage = response as IXtextWebPushMessage;
51 return typeof pushMessage.resource === 'string'
52 && typeof pushMessage.stateId === 'string'
53 && typeof pushMessage.service === 'string'
54 && typeof pushMessage.push !== 'undefined';
55}