1
0
mirror of https://github.com/pavlobu/deskreen.git synced 2025-05-18 08:20:10 -07:00
deskreen/app/server/store/MemoryStore.ts
2020-12-25 01:11:01 +02:00

57 lines
1.1 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
/*
* original JS code from darkwire.io
* translated to typescript for Deskreen app
* */
interface MemoryStoreParams {
store: unknown;
}
class MemoryStore implements MemoryStoreParams {
store: any;
constructor() {
this.store = {};
}
async get(key: string, field: any) {
if (this.store[key] === undefined || this.store[key][field] === undefined) {
return null;
}
return this.store[key][field];
}
async getAll(key: string) {
if (this.store[key] === undefined) {
return [];
}
return this.store[key];
}
async set(key: string, field: string, value: any) {
if (this.store[key] === undefined) {
this.store[key] = {};
}
this.store[key][field] = value;
return 1;
}
async del(key: string, field: string) {
if (this.store[key] === undefined || this.store[key][field] === undefined) {
return 0;
}
delete this.store[key][field];
return 1;
}
async inc(key: string, field: string, inc = 1) {
this.store[key][field] += inc;
return this.store[key][field];
}
}
export default MemoryStore;