You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-29 22:48:10 +02:00
Tools: Apply rule @typescript-eslint/type-annotation-spacing
This commit is contained in:
@@ -8,10 +8,10 @@ enum ValueType {
|
||||
|
||||
export default class KvStore extends BaseService {
|
||||
|
||||
private incMutex_:any = null
|
||||
private db_:any = null;
|
||||
private incMutex_: any = null
|
||||
private db_: any = null;
|
||||
|
||||
private static instance_:KvStore = null;
|
||||
private static instance_: KvStore = null;
|
||||
|
||||
public static instance() {
|
||||
if (this.instance_) return this.instance_;
|
||||
@@ -28,7 +28,7 @@ export default class KvStore extends BaseService {
|
||||
this.incMutex_ = new Mutex();
|
||||
}
|
||||
|
||||
public setDb(v:any) {
|
||||
public setDb(v: any) {
|
||||
this.db_ = v;
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ export default class KvStore extends BaseService {
|
||||
return this.db_;
|
||||
}
|
||||
|
||||
private typeFromValue_(value:any) {
|
||||
private typeFromValue_(value: any) {
|
||||
if (typeof value === 'string') return ValueType.Text;
|
||||
if (typeof value === 'number') return ValueType.Int;
|
||||
throw new Error(`Unsupported value type: ${typeof value}`);
|
||||
}
|
||||
|
||||
private formatValues_(kvs:any[]) {
|
||||
private formatValues_(kvs: any[]) {
|
||||
const output = [];
|
||||
for (const kv of kvs) {
|
||||
kv.value = this.formatValue_(kv.value, kv.type);
|
||||
@@ -52,28 +52,28 @@ export default class KvStore extends BaseService {
|
||||
return output;
|
||||
}
|
||||
|
||||
private formatValue_(value:any, type:ValueType):string | number {
|
||||
private formatValue_(value: any, type: ValueType): string | number {
|
||||
if (type === ValueType.Int) return Number(value);
|
||||
if (type === ValueType.Text) return `${value}`;
|
||||
throw new Error(`Unknown type: ${type}`);
|
||||
}
|
||||
|
||||
public async value<T>(key:string):Promise<T> {
|
||||
public async value<T>(key: string): Promise<T> {
|
||||
const r = await this.db().selectOne('SELECT `value`, `type` FROM key_values WHERE `key` = ?', [key]);
|
||||
if (!r) return null;
|
||||
return this.formatValue_(r.value, r.type) as any;
|
||||
}
|
||||
|
||||
public async setValue(key:string, value:any) {
|
||||
public async setValue(key: string, value: any) {
|
||||
const t = Date.now();
|
||||
await this.db().exec('INSERT OR REPLACE INTO key_values (`key`, `value`, `type`, `updated_time`) VALUES (?, ?, ?, ?)', [key, value, this.typeFromValue_(value), t]);
|
||||
}
|
||||
|
||||
public async deleteValue(key:string) {
|
||||
public async deleteValue(key: string) {
|
||||
await this.db().exec('DELETE FROM key_values WHERE `key` = ?', [key]);
|
||||
}
|
||||
|
||||
public async deleteByPrefix(prefix:string) {
|
||||
public async deleteByPrefix(prefix: string) {
|
||||
await this.db().exec('DELETE FROM key_values WHERE `key` LIKE ?', [`${prefix}%`]);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ export default class KvStore extends BaseService {
|
||||
|
||||
// Note: atomicity is done at application level so two difference instances
|
||||
// accessing the db at the same time could mess up the increment.
|
||||
public async incValue(key:string, inc:number = 1) {
|
||||
public async incValue(key: string, inc: number = 1) {
|
||||
const release = await this.incMutex_.acquire();
|
||||
|
||||
try {
|
||||
@@ -102,7 +102,7 @@ export default class KvStore extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
public async searchByPrefix(prefix:string) {
|
||||
public async searchByPrefix(prefix: string) {
|
||||
const results = await this.db().selectAll('SELECT `key`, `value`, `type` FROM key_values WHERE `key` LIKE ?', [`${prefix}%`]);
|
||||
return this.formatValues_(results);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user