aboutsummaryrefslogtreecommitdiffstats
path: root/packages/shared/src/stores/ServiceState.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/shared/src/stores/ServiceState.ts')
-rw-r--r--packages/shared/src/stores/ServiceState.ts72
1 files changed, 72 insertions, 0 deletions
diff --git a/packages/shared/src/stores/ServiceState.ts b/packages/shared/src/stores/ServiceState.ts
new file mode 100644
index 0000000..d311a70
--- /dev/null
+++ b/packages/shared/src/stores/ServiceState.ts
@@ -0,0 +1,72 @@
1/*
2 * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com>
3 *
4 * This file is part of Sophie.
5 *
6 * Sophie is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: AGPL-3.0-only
19 */
20
21import { Instance, SnapshotIn, types } from 'mobx-state-tree';
22
23import Certificate from './Certificate.js';
24
25const ServiceState = /* @__PURE__ */ (() =>
26 types.optional(
27 types.union(
28 types.model('ServiceInitializingState', {
29 type: types.literal('initializing'),
30 }),
31 types.model('ServiceLoadingState', {
32 type: types.literal('loading'),
33 }),
34 types.model('ServiceLoadedState', {
35 type: types.literal('loaded'),
36 }),
37 types.model('ServiceFailedState', {
38 type: types.literal('failed'),
39 errorCode: types.integer,
40 errorDesc: types.string,
41 }),
42 types.model('ServiceCertificateErrorState', {
43 type: types.literal('certificateError'),
44 errorCode: types.string,
45 certificate: Certificate,
46 trust: types.optional(
47 types.union(
48 types.literal('pending'),
49 types.literal('rejected'),
50 types.literal('accepted'),
51 ),
52 'pending',
53 ),
54 }),
55 types.model({
56 type: types.literal('crashed'),
57 reason: types.string,
58 exitCode: types.integer,
59 }),
60 ),
61 { type: 'initializing' },
62 ))();
63
64/*
65 eslint-disable-next-line @typescript-eslint/no-redeclare --
66 Intentionally naming the type the same as the store definition.
67*/
68type ServiceState = Instance<typeof ServiceState>;
69
70export default ServiceState;
71
72export type ServiceStateSnapshotIn = SnapshotIn<typeof ServiceState>;