import { ClusterClient , Collections , ShardClient } from 'detritus-client' ; import { EventSubscription } from 'detritus-utils' ; import { DIRECTORY } from '../../config.json' ; import RedisClient , { RedisSpewer } from '../redis' ; export class Store < K , V > extends Collections . BaseCollection < K , V > { subscriptions : Array < EventSubscription > = [ ] ; connect ( cluster ) { const subscriptions = this . create ( cluster , RedisClient ) ; for ( let subscription of subscriptions ) { this . subscriptions . push ( subscription ) ; } } create ( cluster , redis ) { return [ ] ; } stop ( cluster ) { while ( this . subscriptions . length ) { const subscription = this . subscriptions . shift ( ) ; if ( subscription ) { subscription . remove ( ) ; } } } } export function connectAllStores ( cluster ) { for ( let key in require . cache ) { if ( key . includes ( `${ DIRECTORY }/stores/` ) ) { const { default : store } = require ( key ) || { } ; if ( store && store instanceof Store ) { store . connect ( cluster ) ; } } } }