UNPKG

609 BPlain TextView Raw
1import { create as createLogger } from '../common/log'
2const log = createLogger('memdown-store')
3
4class MemoryStore {
5 db: Map<string, string> = new Map()
6
7 constructor () {
8 log.info('initialize in-memory database.')
9 log.warn('(!!!) balances and other important state will NOT persist across sessions. DO NOT DO THIS IN PRODUCTION!')
10 }
11
12 async get (key: string): Promise<string | undefined> {
13 return this.db.get(key)
14 }
15
16 async put (key: string, value: string) {
17 return this.db.set(key, value)
18 }
19
20 async del (key: string) {
21 return this.db.delete(key)
22 }
23}
24
25export = MemoryStore