diff options
Diffstat (limited to 'language-web/src/main/js/editor/xtextMessages.ts')
-rw-r--r-- | language-web/src/main/js/editor/xtextMessages.ts | 55 |
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 @@ | |||
1 | export interface IXtextWebRequest { | ||
2 | id: string; | ||
3 | |||
4 | request: unknown; | ||
5 | } | ||
6 | |||
7 | export interface IXtextWebOkResponse { | ||
8 | id: string; | ||
9 | |||
10 | response: unknown; | ||
11 | } | ||
12 | |||
13 | export 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 | |||
19 | export const VALID_XTEXT_WEB_ERROR_KINDS = ['request', 'server'] as const; | ||
20 | |||
21 | export type XtextWebErrorKind = typeof VALID_XTEXT_WEB_ERROR_KINDS[number]; | ||
22 | |||
23 | export interface IXtextWebErrorResponse { | ||
24 | id: string; | ||
25 | |||
26 | error: XtextWebErrorKind; | ||
27 | |||
28 | message: string; | ||
29 | } | ||
30 | |||
31 | export 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 | |||
39 | export interface IXtextWebPushMessage { | ||
40 | resource: string; | ||
41 | |||
42 | stateId: string; | ||
43 | |||
44 | service: string; | ||
45 | |||
46 | push: unknown; | ||
47 | } | ||
48 | |||
49 | export 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 | } | ||