import { PROXY_MODE } from '../constants' ; /**
 * TODO: This interface needs to be updated with values from  RemoteInfo provided
 * by the @elastic/elasticsearch client
  export interface ClusterInfoEs { seeds ? : string [ ] ; mode ? : 'proxy' | 'sniff' ; connected ? : boolean ; num_nodes_connected ? : number ; max_connections_per_cluster ? : string | number ; initial_connect_timeout : string | number ; skip_unavailable ? : boolean ; transport ? : { ping_schedule ? : string ; compress ? : boolean ; } ; proxy_address ? : string ; max_proxy_socket_connections ? : number ; num_proxy_sockets_connected ? : number ; server_name ? : string ; } export interface Cluster { name : string ; seeds ? : string [ ] ; skipUnavailable ? : boolean ; nodeConnections ? : number ; proxyAddress ? : string ; proxySocketConnections ? : number ; serverName ? : string ; mode ? : 'proxy' | 'sniff' ; isConnected ? : boolean ; transportPingSchedule ? : string ; transportCompress ? : boolean ; connectedNodesCount ? : number ; maxConnectionsPerCluster ? : string | number ; initialConnectTimeout ? : string | number ; connectedSocketsCount ? : number ; hasDeprecatedProxySetting ? : boolean ; } export interface ClusterPayloadEs { skip_unavailable ? : boolean | null ; mode ? : 'sniff' | 'proxy' | null ; proxy_address ? : string | null ; proxy_socket_connections ? : number | null ; server_name ? : string | null ; seeds ? : string [ ] | null ; node_connections ? : number | null ; proxy ? : null ; } export interface ClusterSettingsPayloadEs { persistent : { cluster : { remote : { [ key ] : ClusterPayloadEs ; } ; } ; } ; } export function deserializeCluster ( name , esClusterObject , deprecatedProxyAddress ? , isCloudEnabled ? ) { if ( ! name || ! esClusterObject || typeof esClusterObject !== 'object' ) { throw new Error ( 'Unable to deserialize cluster' ) ; } const { seeds , mode , connected : isConnected , num_nodes_connected : connectedNodesCount , max_connections_per_cluster : maxConnectionsPerCluster , initial_connect_timeout : initialConnectTimeout , skip_unavailable : skipUnavailable , transport , proxy_address : proxyAddress , max_proxy_socket_connections : proxySocketConnections , num_proxy_sockets_connected : connectedSocketsCount , server_name : serverName , } = esClusterObject ; let deserializedClusterObject = { name , mode , isConnected , connectedNodesCount , maxConnectionsPerCluster , initialConnectTimeout , skipUnavailable , seeds , proxyAddress , proxySocketConnections , connectedSocketsCount , serverName , } ; if ( transport ) { const { ping_schedule : transportPingSchedule , compress : transportCompress } = transport ; deserializedClusterObject = { ... deserializedClusterObject , transportPingSchedule , transportCompress , } ; } if ( deprecatedProxyAddress ) { const defaultServerName = deprecatedProxyAddress . split ( ':' ) [ 0 ] ; deserializedClusterObject = { ... deserializedClusterObject , proxyAddress : deprecatedProxyAddress , seeds : undefined , hasDeprecatedProxySetting : true , mode : PROXY_MODE , serverName : isCloudEnabled ? defaultServerName : undefined , } ; } Object . keys ( deserializedClusterObject ) . forEach ( ( key ) => { if ( deserializedClusterObject [ key as keyof Cluster ] === undefined ) { delete deserializedClusterObject [ key as keyof Cluster ] ; } } ) ; return deserializedClusterObject ; } export function serializeCluster ( deserializedClusterObject ) { if ( ! deserializedClusterObject || typeof deserializedClusterObject !== 'object' ) { throw new Error ( 'Unable to serialize cluster' ) ; } const { name , seeds , skipUnavailable , mode , nodeConnections , proxyAddress , proxySocketConnections , serverName , hasDeprecatedProxySetting , } = deserializedClusterObject ; const clusterData = { skip_unavailable : typeof skipUnavailable === 'boolean' ? skipUnavailable : null , mode : mode || null , proxy_address : proxyAddress || null , proxy_socket_connections : proxySocketConnections || null , server_name : serverName || null , seeds : seeds || null , node_connections : nodeConnections || null , } ; if ( hasDeprecatedProxySetting ) { clusterData . proxy = null ; } return { persistent : { cluster : { remote : { [ name ] : clusterData , } , } , } , } ; }