import {Instantiable, isInstantiable} from '../di' import {AuthenticatableRepository} from './types' import {hasOwnProperty} from '../util' export interface AuthenticationConfig { storage: Instantiable, sources?: { [key: string]: Instantiable, }, } export function isAuthenticationConfig(what: unknown): what is AuthenticationConfig { if ( typeof what !== 'object' || !what ) { return false } if ( !hasOwnProperty(what, 'storage') || !hasOwnProperty(what, 'sources') ) { return false } if ( !isInstantiable(what.storage) || !(what.storage.prototype instanceof AuthenticatableRepository) ) { return false } if ( typeof what.sources !== 'object' ) { return false } for ( const key in what.sources ) { if ( !hasOwnProperty(what.sources, key) ) { continue } const source = what.sources[key] if ( !isInstantiable(source) || !(source.prototype instanceof AuthenticatableRepository) ) { return false } } return true }