aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/persistence/compressionMessages.tsx
blob: 37c6e8cd6c51d241bcb2f6f042554a4df908978e (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: 2023 The Refinery Authors <https://refinery.tools/>
 *
 * SPDX-License-Identifier: EPL-2.0
 */

import { z } from 'zod';

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

export const CompressRequest = z.object({
  request: z.literal('compress'),
  text: z.string(),
});

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

export const DecompressRequest = z.object({
  request: z.literal('decompress'),
  compressedText: z.string(),
});

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

export const CompressorRequest = z.union([CompressRequest, DecompressRequest]);

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

export const CompressResponse = z.object({
  response: z.literal('compressed'),
  compressedText: z.string(),
});

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

export const DecompressResponse = z.object({
  response: z.literal('decompressed'),
  text: z.string(),
});

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

export const ErrorResponse = z.object({
  response: z.literal('error'),
  message: z.string(),
});

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

export const CompressorResponse = z.union([
  CompressResponse,
  DecompressResponse,
  ErrorResponse,
]);

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