forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoption-database.ts
More file actions
34 lines (27 loc) · 905 Bytes
/
Copy pathoption-database.ts
File metadata and controls
34 lines (27 loc) · 905 Bytes
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
/**
* Copyright (c) 2021 Hengyang Zhang
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
import { defaultOption } from "@util/constant/option"
import { mergeObject } from '@util/lang'
import BaseDatabase from "./common/base-database"
import { REMAIN_WORD_PREFIX } from "./common/constant"
const DB_KEY = REMAIN_WORD_PREFIX + 'OPTION'
/**
* Database of options
*
* @since 0.3.0
*/
class OptionDatabase extends BaseDatabase {
async getOption(): Promise<tt4b.option.AllOption> {
const option = await this.storage.getOne<tt4b.option.AllOption>(DB_KEY)
return mergeObject<tt4b.option.AllOption>(defaultOption(), option)
}
async setOption(option: tt4b.option.AllOption): Promise<void> {
option && await this.setByKey(DB_KEY, option)
}
}
const optionDatabase = new OptionDatabase()
export default optionDatabase