import { RulesValidationError } from '../error_handling/RulesValidationError' ; export class RulesPermissionModel { param block param allow constructor ( public block ? , public allow ? ) { } param input public static create ( input ) { const instance = new RulesPermissionModel ( ) ; instance . populateFrom ( input ) ; return instance ; } param input public populateFrom ( input ) { const { allow , block } = input ; this . allow = RulesPermissionModel . validateDidList ( allow ) ; this . block = RulesPermissionModel . validateDidList ( block ) ; if ( ! ( this . allow || this . block ) ) { throw new RulesValidationError ( 'Empty permissions models are not allowed.' ) ; } } private static validateDidList ( didList ? ) { if ( ! didList ) { return undefined ; } const uniqueDids = new Set ( didList ) ; if ( uniqueDids . size !== didList . length ) { throw new RulesValidationError ( 'Non-unique DID(s) found in one or more permission lists.' ) ; } return didList ; } }