import { injectable } from '@cloudbeaver/core-di' ; import { GraphQLService , CachedDataResource , SessionStateFragment } from '@cloudbeaver/core-sdk' ; import { ServerConfigResource } from './ServerConfigResource' ; export type SessionState = SessionStateFragment ; @ injectable ( ) export class SessionResource extends CachedDataResource < SessionState | null , void > { private defaultLocale : string | undefined ; constructor ( private graphQLService , serverConfigResource ) { super ( null ) ; this . sync ( serverConfigResource ) ; } setDefaultLocale ( defaultLocale ? ) { this . defaultLocale = defaultLocale ; } async refreshSilent ( ) { const { session } = await this . graphQLService . sdk . openSession ( { defaultLocale : this . defaultLocale } ) ; this . setData ( session ) ; } async changeLanguage ( locale ) { await this . performUpdate ( undefined , undefined , async ( ) => { await this . graphQLService . sdk . changeSessionLanguage ( { locale } ) ; this . defaultLocale = locale ; if ( this . data ) { this . data . locale = locale ; } } ) ; } protected async loader ( ) { const { session } = await this . graphQLService . sdk . openSession ( { defaultLocale : this . defaultLocale } ) ; return session ; } }