import { createLazy } from 'common/utils/lazy.light' ; import Firebase from 'common/services/firebase' ; import { DBProvider , UserRepo , CoachRepo , ClientRepo , ClientCardRepo , RecordRepo , StaticTipsRepo , } from 'common/database/repositories' ; const PROXIES_PREFIX = 'proxies' ; interface IRepoConstructor < T > { new ( provider ) : T ; } type RepoType < T > = { [ P in keyof T ] : ( ( ... args : any [ ] ) => Promise < any > ) | any ; } ; const instance = createLazy ( ( ) => new RepoFactory ( false ) ) ; export default class RepoFactory { static get Instance ( ) { return instance . value ; } private readonly _users = createLazy ( ( ) => new UserRepo ( Firebase . Instance . database ) ) ; private readonly _coaches = createLazy ( ( ) => new CoachRepo ( Firebase . Instance . database ) ) ; private readonly _clients = createLazy ( ( ) => new ClientRepo ( Firebase . Instance . database ) ) ; private readonly _clientCards = createLazy ( ( ) => new ClientCardRepo ( Firebase . Instance . database ) ) ; private readonly _records = createLazy ( ( ) => new RecordRepo ( Firebase . Instance . database ) ) ; private readonly _staticTips = createLazy ( ( ) => new StaticTipsRepo ( Firebase . Instance . database ) ) ; constructor ( private readonly useProxy ) { } get users ( ) : UserRepo { return this . _users . value ; } get coaches ( ) : CoachRepo { return this . _coaches . value ; } get clients ( ) : ClientRepo { return this . _clients . value ; } get clientCards ( ) : ClientCardRepo { return this . _clientCards . value ; } get records ( ) : RecordRepo { return this . _records . value ; } get staticTips ( ) : StaticTipsRepo { return this . _staticTips . value ; } }