import { EventEmitter } from 'events' import { Base, TYPES } from './base' import Hsah from './hash' import List from './list' import Set from './set' import SortedSet from './zset' import { Multi } from './mise' export class MinDB extends EventEmitter implements Base, Hsah, List, Set, SortedSet { constructor(...args: any[]) { super() Base.call(this, ...args) } name: string store: LocalForage _keys: { [key: string]: TYPES } _setType: () => Promise _delType: () => Promise _restoreKeys: () => Promise exists: (key: string) => Promise is: (key: string, type: TYPES) => Promise renamenx: (key: string, newKey: string) => Promise rename: (key: string, newKey: string) => Promise set: (key: string, value: any) => Promise setnx: (key: string, value: any) => Promise setex: (key: string, seconds: number, value: any) => Promise psetex: (key: string, milliseconds: number, value: any) => Promise mset: (doc: { [key: string]: any }) => Promise append: (key: string, value: string) => Promise get: (key: string) => Promise getrange: (key: string, start: number, end: number) => Promise mget: (keys: string[]) => Promise getset: (key: string, value: any) => Promise strlen: (key: string) => Promise incr: (key: string) => Promise del: (key: string) => Promise keys: (pattern?: string) => Promise randomKey: () => Promise type: (key: string) => Promise empty: () => Promise hset: (key: string, field: string, value: any) => Promise hsetnx: (key: string, field: string, value: any) => Promise hexists: (key: string, field: string) => Promise hmset: (key: string, doc: { [field: string]: any }) => Promise hget: (key: string, field: string) => Promise hmget: (key: string, fields: string[]) => Promise hgetall: (key: string) => Promise<{ [field: string]: any }> hdel: (key: string, field: string) => Promise hlen: (key: string) => Promise hkeys: (key: string) => Promise hincr: (key: string, field: string) => Promise hincrby: (key: string, field: string, increment: number) => Promise hincrbyfloat: (key: string, field: string, increment: number) => Promise hdecr: (key: string, field: string) => Promise hdecrby: (key: string, field: string, decrement: number) => Promise hdecrbyfloat: (key: string, field: string, decrement: number) => Promise lpush: (key: string, ...values: any[]) => Promise lpushx: (key: string, ...values: any[]) => Promise rpush: (key: string, ...values: any[]) => Promise rpushx: (key: string, ...values: any[]) => Promise lpop: (key: string) => Promise rpop: (key: string) => Promise llen: (key: string) => Promise lrange: (key: string, start: number, stop: number) => Promise lrem: (key: string, count: number, value: any) => Promise lset: (key: string, index: number, value: any) => Promise ltrim: (key: string, start: number, stop: number) => Promise lindex: (key: string, index: number) => Promise linsertBefore: (key: string, pivot: any, value: any) => Promise linsertAfter: (key: string, pivot: any, value: any) => Promise rpoplpush: (src: string, dest: string) => Promise lpoprpush: (src: string, dest: string) => Promise sadd: (key: string, ...members: any[]) => Promise srem: (key: string, ...members: any[]) => Promise smembers: (key: string) => Promise sismember: (key: string, value: any) => Promise scard: (key: string) => Promise smove: (src: string, dest: string, member: any) => Promise srandmember: (key: string) => Promise spop: (key: string) => Promise sunion: (...keys: string[]) => Promise sunionstore: (dest: string, ...keys: string[]) => Promise sinter: (...keys: string[]) => Promise sinterstore: (dest: string, ...keys: string[]) => Promise sdiff: (...keys: string[]) => Promise sdiffstore: (dest: string, ...keys: string[]) => Promise zadd: (key: string, score: number, member: any) => Promise<0 | 1> zcard: (key: string) => Promise zcount: (key: string, min: number, max: number) => Promise zrem: (key: string, ...members: any[]) => Promise zscore: (key: string, member: any) => Promise zrange: (key: string, min: number, max: number) => Promise zrevrange: (key: string, min: number, max: number) => Promise zincrby: (key: string, increment: number, member: any) => Promise zdecrby: (key: string, decrement: number, member: any) => Promise zrank: (key: string, member: any) => Promise zrevrank: (key: string, member: any) => Promise multi() { return new Multi(this) } } applyMixins(MinDB, [ Base, Hsah, List, Set, SortedSet ]) export default new MinDB() function applyMixins(derivedCtor: any, baseCtors: any[]) { baseCtors.forEach(baseCtor => { Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => { derivedCtor.prototype[name] = baseCtor.prototype[name] }) }) }