aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/xtext/xtextMessages.ts
blob: bbbff06482571e7dd860ac61f1ae186278b4e554 (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
/*
 * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
 *
 * SPDX-License-Identifier: EPL-2.0
 */

/* eslint-disable @typescript-eslint/no-redeclare -- Declare types with their companion objects */

import { z } from 'zod';

export const XtextWebRequest = z.object({
  id: z.string().min(1),
  request: z.unknown(),
});

export type XtextWebRequest = z.infer<typeof XtextWebRequest>;

export const XtextWebOkResponse = z.object({
  id: z.string().min(1),
  response: z.unknown(),
});

export type XtextWebOkResponse = z.infer<typeof XtextWebOkResponse>;

export const XtextWebErrorKind = z.enum(['request', 'server']);

export type XtextWebErrorKind = z.infer<typeof XtextWebErrorKind>;

export const XtextWebErrorResponse = z.object({
  id: z.string().min(1),
  error: XtextWebErrorKind,
  message: z.string(),
});

export type XtextWebErrorResponse = z.infer<typeof XtextWebErrorResponse>;

export const XtextWebPushService = z.enum(['highlight', 'validate']);

export type XtextWebPushService = z.infer<typeof XtextWebPushService>;

export const XtextWebPushMessage = z.object({
  resource: z.string().min(1),
  stateId: z.string().min(1),
  service: XtextWebPushService,
  push: z.unknown(),
});

export type XtextWebPushMessage = z.infer<typeof XtextWebPushMessage>;

export const XtextResponse = z.union([
  XtextWebOkResponse,
  XtextWebErrorResponse,
  XtextWebPushMessage,
]);

export type XtextResponse = z.infer<typeof XtextResponse>;