import { ActivePairStore , OrderPair } from './types' ; import { reviveOrder } from './OrderImpl' ; import { ChronoDB , TimeSeries } from '@bitr/chronodb' ; import { EventEmitter } from 'events' ; class EmittableActivePairStore extends EventEmitter implements ActivePairStore { timeSeries : TimeSeries < OrderPair > ; constructor ( chronoDB ) { super ( ) ; this . timeSeries = chronoDB . getTimeSeries < OrderPair > ( 'ActivePair' , orderPair => orderPair . map ( o => reviveOrder ( o ) ) as OrderPair ) ; } get ( key ) { return this . timeSeries . get ( key ) ; } getAll ( ) { return this . timeSeries . getAll ( ) ; } put ( value ) { this . emit ( 'change' ) ; return this . timeSeries . put ( value ) ; } del ( key ) { this . emit ( 'change' ) ; return this . timeSeries . del ( key ) ; } delAll ( ) { this . emit ( 'change' ) ; return this . timeSeries . delAll ( ) ; } } export const getActivePairStore = ( chronoDB ) : ActivePairStore => new EmittableActivePairStore ( chronoDB ) ;