-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsettings-data.ts
94 lines (89 loc) · 2.36 KB
/
settings-data.ts
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
import {
type Fixed,
NOTICE_NO_TIMEOUT,
NULL_SEM_VER_STRING,
PluginContext,
type SemVerString,
cloneAsWritable,
deepFreeze,
fixInSet,
fixTyped,
launderUnchecked,
markFixed,
opaqueOrDefault,
semVerString,
} from "@polyipseity/obsidian-plugin-library"
import type { MarkOptional } from "ts-essentials"
import { PluginLocales } from "../assets/locales.js"
export interface LocalSettings extends PluginContext.LocalSettings {
readonly lastReadChangelogVersion: SemVerString
}
export namespace LocalSettings {
export function fix(self0: unknown): Fixed<LocalSettings> {
const unc = launderUnchecked<LocalSettings>(self0)
return markFixed(self0, {
...PluginContext.LocalSettings.fix(self0).value,
lastReadChangelogVersion: opaqueOrDefault(
semVerString,
String(unc.lastReadChangelogVersion),
NULL_SEM_VER_STRING,
),
})
}
}
export interface Settings extends PluginContext.Settings {
readonly language: Settings.DefaultableLanguage
readonly openChangelogOnUpdate: boolean
}
export namespace Settings {
export const optionals = deepFreeze([]) satisfies readonly (keyof Settings)[]
export type Optionals = typeof optionals[number]
export type Persistent = Omit<Settings, Optionals>
export function persistent(settings: Settings): Persistent {
const ret: MarkOptional<Settings, Optionals> = cloneAsWritable(settings)
for (const optional of optionals) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete ret[optional]
}
return ret
}
export const DEFAULT: Persistent = deepFreeze({
errorNoticeTimeout: NOTICE_NO_TIMEOUT,
language: "",
noticeTimeout: 5,
openChangelogOnUpdate: true,
})
export const DEFAULTABLE_LANGUAGES =
deepFreeze(["", ...PluginLocales.LANGUAGES])
export type DefaultableLanguage = typeof DEFAULTABLE_LANGUAGES[number]
export function fix(self0: unknown): Fixed<Settings> {
const unc = launderUnchecked<Settings>(self0)
return markFixed(self0, {
...PluginContext.Settings.fix(self0).value,
errorNoticeTimeout: fixTyped(
DEFAULT,
unc,
"errorNoticeTimeout",
["number"],
),
language: fixInSet(
DEFAULT,
unc,
"language",
DEFAULTABLE_LANGUAGES,
),
noticeTimeout: fixTyped(
DEFAULT,
unc,
"noticeTimeout",
["number"],
),
openChangelogOnUpdate: fixTyped(
DEFAULT,
unc,
"openChangelogOnUpdate",
["boolean"],
),
})
}
}