import { injectable } from '@cloudbeaver/core-di' ; import { ExecutorInterrupter } from '@cloudbeaver/core-executor' ; import { GraphQLService , CachedDataResource , CachedResource } from '@cloudbeaver/core-sdk' ; import { SessionDataResource } from './SessionDataResource' ; @ injectable ( ) export class PermissionsResource extends CachedDataResource < Set < string > > { constructor ( private graphQLService , sessionDataResource ) { super ( new Set ( ) ) ; this . sync ( sessionDataResource ) ; } require ( resource , ... permissions ) { resource . preloadResource ( this , ( ) => undefined ) . before ( ExecutorInterrupter . interrupter ( ( ) => ! this . has ( ... permissions ) ) ) ; return this ; } has ( ... permissions ) { return ! permissions . some ( permission => ! this . data . has ( permission ) ) ; } async hasAsync ( id ) { await this . load ( ) ; return this . has ( id ) ; } protected async loader ( ) { const { permissions } = await this . graphQLService . sdk . sessionPermissions ( ) ; this . data . clear ( ) ; for ( const permission of permissions ) { this . data . add ( permission ) ; } return this . data ; } }