import * as _ from 'lodash' ; import * as mock from 'mock-require' ; interface ValuesProps { [ key ] : string ; } let _values ; let pushCount ; reset ( ) ; export function reset ( ) { _values = { } ; pushCount = 0 ; } export function has ( path ) { return _values . hasOwnProperty ( path ) ; } export function get ( path ) { if ( ! _values . hasOwnProperty ( path ) ) { return Promise . resolve ( null ) ; } return Promise . resolve ( _values [ path ] ) ; } export function set ( path , value ) { _values [ path ] = value ; return Promise . resolve ( ) ; } export function push ( path , value ) { _values [ `${ path }/pushprefix-${ pushCount }` ] = value ; pushCount ++ ; return Promise . resolve ( ) ; } export function remove ( path ) { delete _values [ path ] ; return Promise . resolve ( ) ; } export async function transaction ( path , callback ) { return set ( path , callback ( await get ( path ) ) ) ; } export function values ( ) { return _values ; } export function init ( otherModule ) { mock ( otherModule , './fake-db' ) ; }