import { window , workspace } from 'vscode' ; import { getExtensionContext } from './extensionContext' ; import { KnownClusterProviders } from './kubernetes/kubernetesTypes' ; export interface ClusterMetadata { azureResourceGroup ? : string ; azureSubscription ? : string ; azureClusterName ? : string ; clusterProvider ? : KnownClusterProviders ; } const enum GlobalStatePrefixes { ClusterMetadata = 'clusterMetadata' } /**
 * TODO: keep context as property
 */ class GlobalState { private prefix ( prefixValue , str ) { return `${ prefixValue }:${ str }` ; } get ( stateKey ) { return getExtensionContext ( ) . globalState . get ( stateKey ) ; } set ( stateKey , newValue ) { getExtensionContext ( ) . globalState . update ( stateKey , newValue ) ; } getClusterMetadata ( clusterName ) { return this . get ( this . prefix ( GlobalStatePrefixes . ClusterMetadata , clusterName ) ) as ClusterMetadata | undefined ; } setClusterMetadata ( clusterName , metadata ) { this . set ( this . prefix ( GlobalStatePrefixes . ClusterMetadata , clusterName ) , metadata ) ; } /**
     * Run while developing to see the entire global storage contents.
     */ async showGlobalStateValue ( ) { const document = await workspace . openTextDocument ( { language : 'jsonc' , content : JSON . stringify ( getExtensionContext ( ) . globalState . _value , null , '  ' ) , } ) ; window . showTextDocument ( document ) ; } /**
     * Dev function (clear all global state properties).
     */ clearGlobalState ( ) { for ( const key of getExtensionContext ( ) . globalState . keys ( ) ) { this . set ( key , undefined ) ; } } } /**
 * Global state (saved in vscode global storage).
 */ export const globalState = new GlobalState ( ) ;