2018-06-09 03:22:39 +00:00
|
|
|
// @flow
|
2018-06-25 17:42:50 +00:00
|
|
|
import type { Plugin } from '../index';
|
2018-06-09 03:22:39 +00:00
|
|
|
import * as models from '../../models';
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function init(plugin: Plugin) {
|
2018-06-09 03:22:39 +00:00
|
|
|
return {
|
|
|
|
store: {
|
2018-06-25 17:42:50 +00:00
|
|
|
async hasItem(key: string): Promise<boolean> {
|
2018-06-09 03:22:39 +00:00
|
|
|
const doc = await models.pluginData.getByKey(plugin.name, key);
|
|
|
|
return doc !== null;
|
|
|
|
},
|
2018-06-25 17:42:50 +00:00
|
|
|
async setItem(key: string, value: string): Promise<void> {
|
2018-06-09 03:22:39 +00:00
|
|
|
await models.pluginData.upsertByKey(plugin.name, key, String(value));
|
|
|
|
},
|
2018-06-25 17:42:50 +00:00
|
|
|
async getItem(key: string): Promise<string | null> {
|
2018-06-09 03:22:39 +00:00
|
|
|
const doc = await models.pluginData.getByKey(plugin.name, key);
|
|
|
|
return doc ? doc.value : null;
|
|
|
|
},
|
2018-06-25 17:42:50 +00:00
|
|
|
async removeItem(key: string): Promise<void> {
|
2018-06-09 03:22:39 +00:00
|
|
|
await models.pluginData.removeByKey(plugin.name, key);
|
2018-06-27 04:58:34 +00:00
|
|
|
},
|
|
|
|
async clear(key: string): Promise<void> {
|
|
|
|
await models.pluginData.removeAll(plugin.name);
|
2018-06-09 03:22:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|