From dcbfeece5e559b60a615f0aa9b933b202d34bf8b Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Mon, 25 Oct 2021 00:29:37 +0200 Subject: feat(web): add xtext websocket client --- language-web/src/main/js/editor/xtextMessages.ts | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 language-web/src/main/js/editor/xtextMessages.ts (limited to 'language-web/src/main/js/editor/xtextMessages.ts') 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 @@ +export interface IXtextWebRequest { + id: string; + + request: unknown; +} + +export interface IXtextWebOkResponse { + id: string; + + response: unknown; +} + +export function isOkResponse(response: unknown): response is IXtextWebOkResponse { + const okResponse = response as IXtextWebOkResponse; + return typeof okResponse.id === 'string' + && typeof okResponse.response !== 'undefined'; +} + +export const VALID_XTEXT_WEB_ERROR_KINDS = ['request', 'server'] as const; + +export type XtextWebErrorKind = typeof VALID_XTEXT_WEB_ERROR_KINDS[number]; + +export interface IXtextWebErrorResponse { + id: string; + + error: XtextWebErrorKind; + + message: string; +} + +export function isErrorResponse(response: unknown): response is IXtextWebErrorResponse { + const errorResponse = response as IXtextWebErrorResponse; + return typeof errorResponse.id === 'string' + && typeof errorResponse.error === 'string' + && VALID_XTEXT_WEB_ERROR_KINDS.includes(errorResponse.error) + && typeof errorResponse.message === 'string'; +} + +export interface IXtextWebPushMessage { + resource: string; + + stateId: string; + + service: string; + + push: unknown; +} + +export function isPushMessage(response: unknown): response is IXtextWebPushMessage { + const pushMessage = response as IXtextWebPushMessage; + return typeof pushMessage.resource === 'string' + && typeof pushMessage.stateId === 'string' + && typeof pushMessage.service === 'string' + && typeof pushMessage.push !== 'undefined'; +} -- cgit v1.2.3-70-g09d2