blob: be3125e63c3ed5bd6ab0c3cc7dbc138b537fc811 (
plain) (
blame)
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
|
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 === 'object'
&& 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 === 'object'
&& 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 === 'object'
&& typeof pushMessage.resource === 'string'
&& typeof pushMessage.stateId === 'string'
&& typeof pushMessage.service === 'string'
&& typeof pushMessage.push !== 'undefined';
}
|