mirror of
https://github.com/pavlobu/deskreen.git
synced 2025-05-18 08:20:10 -07:00
59 lines
1.2 KiB
TypeScript
59 lines
1.2 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
/**
|
|
* Memory store more for testing purpose than production use.
|
|
*/
|
|
|
|
interface MemoryStoreParams {
|
|
store: any;
|
|
hasSocketAdapter: boolean;
|
|
}
|
|
|
|
class MemoryStore implements MemoryStoreParams {
|
|
store: any;
|
|
|
|
hasSocketAdapter: boolean;
|
|
|
|
constructor() {
|
|
this.store = {};
|
|
this.hasSocketAdapter = false;
|
|
}
|
|
|
|
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;
|