aboutsummaryrefslogtreecommitdiff
path: root/types/ext/settings-modifications.d.ts
blob: e70ff7e89da3bf5b776728abd420dd1634f3285a (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * Copyright (C) 2023-2024  Yomitan Authors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

import type * as Settings from './settings';

export type OptionsScope = {
    scope: OptionsScopeType;
    optionsContext: Settings.OptionsContext | null;
};

export type OptionsScopeType = 'profile' | 'global';

export type Read = {
    path: string;
};

export type ModificationSet = {
    action: 'set';
    path: string;
    value: unknown;
};

export type ModificationDelete = {
    action: 'delete';
    path: string;
};

export type ModificationSwap = {
    action: 'swap';
    path1: string;
    path2: string;
};

export type ModificationSplice = {
    action: 'splice';
    path: string;
    start: number;
    deleteCount: number;
    items: unknown[];
};

export type ModificationPush = {
    action: 'push';
    path: string;
    items: unknown[];
};

export type Modification = (
    ModificationSet |
    ModificationDelete |
    ModificationSwap |
    ModificationSplice |
    ModificationPush
);

export type ScopedRead = Read & OptionsScope;

export type ScopedModificationSet = ModificationSet & OptionsScope;

export type ScopedModificationDelete = ModificationDelete & OptionsScope;

export type ScopedModificationSwap = ModificationSwap & OptionsScope;

export type ScopedModificationSplice = ModificationSplice & OptionsScope;

export type ScopedModificationPush = ModificationPush & OptionsScope;

export type ScopedModification = (
    ScopedModificationSet |
    ScopedModificationDelete |
    ScopedModificationSwap |
    ScopedModificationSplice |
    ScopedModificationPush
);

export type ModificationSetResult = unknown;

export type ModificationDeleteResult = true;

export type ModificationSwapResult = true;

export type ModificationSpliceResult = unknown[];

export type ModificationPushResult = number;

// There is some redundancy with this type currently due to the `unknown`s used in it.
// For now, this is fine, but the types could be improved in the future.
export type ModificationResult = (
    // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
    ModificationSetResult |
    ModificationDeleteResult |
    // eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents
    ModificationSwapResult |
    ModificationSpliceResult |
    ModificationPushResult
);