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,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAK1D;;OAEG;WACW,OAAO,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO;WAIxC,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;CAGnE","file":"connection.d.ts","sourcesContent":["import { PlainVersionedObject } from '../base/versioned-object';\r\nimport { Net } from '../data/net';\r\nimport { Strings } from '../generated/strings';\r\nimport { EnvironmentConnectionTypeInfo, EnvironmentModule } from '../manifest/environment-modules';\r\n\r\n/**\r\n * The connection properties class.\r\n */\r\nexport interface ConnectionProperties extends MsftSme.StringMap<any> {\r\n}\r\n\r\n/**\r\n * The reserved connection property name on server.\r\n */\r\nexport class ConnectionPropertiesName {\r\n    public static readonly PropertyDisplayName = 'displayName';\r\n    public static readonly PropertyName = 'name';\r\n    public static readonly PropertyNetworkName = 'networkName';\r\n    public static readonly DisplayNameLocalhost = 'localhost';\r\n\r\n    /**\r\n     * Check if the display name is localhost.\r\n     *\r\n     * @param properties the connection properties.\r\n     * @returns true if it's localhost.\r\n     */\r\n    public static isDisplayNameLocalhost(properties: ConnectionProperties): boolean {\r\n        return !!properties && properties[ConnectionPropertiesName.PropertyDisplayName] === ConnectionPropertiesName.DisplayNameLocalhost;\r\n    }\r\n\r\n    /**\r\n     * Gets the display name.\r\n     *\r\n     * @param properties the connection properties.\r\n     * @returns the display name property value.\r\n     */\r\n    public static getDisplayName(properties: ConnectionProperties): string {\r\n        return properties && properties[ConnectionPropertiesName.PropertyDisplayName];\r\n    }\r\n\r\n    /**\r\n     * Gets the name.\r\n     *\r\n     * @param properties the connection properties.\r\n     * @returns the name property value.\r\n     */\r\n    public static getName(properties: ConnectionProperties): string {\r\n        return properties && properties[ConnectionPropertiesName.PropertyName];\r\n    }\r\n\r\n    /**\r\n     * Gets the network name.\r\n     *\r\n     * @param properties the connection properties.\r\n     * @returns the network name property value.\r\n     */\r\n    public static getNetworkName(properties: ConnectionProperties): string {\r\n        return properties && properties[ConnectionPropertiesName.PropertyNetworkName];\r\n    }\r\n}\r\n\r\n/**\r\n * The connection attributes class.\r\n */\r\nexport interface ConnectionAttribute {\r\n\r\n    /**\r\n     * The id string of this attribute\r\n     */\r\n    id: string;\r\n\r\n    /**\r\n     * The value of the attribute. used for attributes that can have variable values such as Operating System\r\n     */\r\n    value?: string | number;\r\n}\r\n\r\n/**\r\n * The connection class.\r\n */\r\nexport interface Connection {\r\n\r\n    /**\r\n     * The id of the connection, this is unique per connection\r\n     */\r\n    id: string;\r\n\r\n    /**\r\n     * The type of connection\r\n     */\r\n    type: string;\r\n\r\n    /**\r\n     * The name of the connection, this is unique per connection type\r\n     */\r\n    name: string;\r\n\r\n    /**\r\n     * The fallback connection aliases list\r\n     */\r\n    aliases?: string[];\r\n\r\n    /**\r\n     * The active alias, last known good name, null or undefined if not in use\r\n     */\r\n    activeAlias?: string;\r\n\r\n    /**\r\n     * The property bag of the connection\r\n     */\r\n    properties?: ConnectionProperties;\r\n\r\n    /**\r\n     * The ids of attributes identified for this connection\r\n     */\r\n    attributes?: ConnectionAttribute[];\r\n\r\n    /**\r\n     * The tags the user(s) have assigned to this connection\r\n     */\r\n    tags?: string[];\r\n\r\n    /**\r\n     * The groupId of the connection\r\n     */\r\n    groupId?: string;\r\n\r\n    /**\r\n     * The settings the users/extensions have assigned to this connection\r\n     */\r\n    settings?: PlainVersionedObject;\r\n\r\n    /**\r\n     * Display type name\r\n     */\r\n    displayTypeName?: string;\r\n}\r\n\r\n/**\r\n * Defines connection type strings known by core\r\n * Be careful that these strings match what is defined by the manifest of @msft-sme/server-manager\r\n */\r\nexport const connectionTypeConstants = {\r\n    server: 'msft.sme.connection-type.server',\r\n    cluster: 'msft.sme.connection-type.cluster',\r\n    windowsClient: 'msft.sme.connection-type.windows-client',\r\n    eflowDevice: 'microsoft.connection-type.eflow-device',\r\n    clusterNodesProperty: 'nodes',\r\n    prefix: 'msft.sme.connection-type.'\r\n};\r\n\r\n/**\r\n * Connection Utility class.\r\n */\r\nexport class ConnectionUtility {\r\n\r\n    /**\r\n     * Determines if one connection is referring to the same object as another connection\r\n     *\r\n     * @param a the first connection in the comparison\r\n     * @param b the second connection in the comparison\r\n     * @returns true if the connections are of the same type and have the same name\r\n     */\r\n    public static areEqual(a: Connection, b: Connection): boolean {\r\n        if (!a || !b) {\r\n            return a === b;\r\n        }\r\n\r\n        if (a.type !== b.type) {\r\n            return false;\r\n        }\r\n\r\n        if (a.name !== b.name) {\r\n            return false;\r\n        }\r\n\r\n        if (a.id !== b.id) {\r\n            return false;\r\n        }\r\n\r\n        return true;\r\n    }\r\n\r\n    /**\r\n     * Determines if the given connection is to a server\r\n     *\r\n     * @param connection the connection to check\r\n     */\r\n    public static isServer(connection: Connection): boolean {\r\n        if (!connection) {\r\n            return false;\r\n        }\r\n        return connection.type === connectionTypeConstants.server;\r\n    }\r\n\r\n    /**\r\n     * Determines if the given connection is to a cluster connection.\r\n     * Currently we support: HCI and Failover Cluster.\r\n     *\r\n     * @param connection the connection to check\r\n     */\r\n    public static isCluster(connection: Connection): boolean {\r\n        if (!connection) {\r\n            return false;\r\n        }\r\n        return connection.type === connectionTypeConstants.cluster;\r\n    }\r\n\r\n    /**\r\n     * Determines if the given connection is to a FailOver cluster\r\n     *\r\n     * @param connection the connection to check\r\n     */\r\n    public static isFailoverCluster(connection: Connection): boolean {\r\n        if (!connection) {\r\n            return false;\r\n        }\r\n        return !MsftSme.isNullOrUndefined(connection.properties) && connection.properties['connectionType'] === 'cluster'\r\n            || (MsftSme.isNullOrUndefined(connection.properties['connectionType']) &&\r\n                connection.type === connectionTypeConstants.cluster);\r\n    }\r\n\r\n    /**\r\n     * Determines if the given connection is to a windows client\r\n     *\r\n     * @param connection the connection to check\r\n     */\r\n    public static isWindowsClient(connection: Connection): boolean {\r\n        if (!connection) {\r\n            return false;\r\n        }\r\n        return connection.type === connectionTypeConstants.windowsClient;\r\n    }\r\n\r\n    /**\r\n     * Determines if the given connection is to an EFLOW device\r\n     *\r\n     * @param connection the connection to check\r\n     */\r\n    public static isEflowDevice(connection: Connection): boolean {\r\n        if (!connection) {\r\n            return false;\r\n        }\r\n        return connection.type === connectionTypeConstants.eflowDevice;\r\n    }\r\n\r\n    /**\r\n     * Determines if the given connection is to a node\r\n     *\r\n     * @param connection the connection to check\r\n     */\r\n    public static isNode(connection: Connection): boolean {\r\n        return this.isServer(connection) || this.isCluster(connection) || this.isWindowsClient(connection)\r\n          || this.isEflowDevice(connection);\r\n    }\r\n\r\n    /**\r\n     * Gets the name of a node from a connection. This assumes the connection is to a single server or cluster.\r\n     *\r\n     * @param connection the connection object. (should be of type server or cluster)\r\n     * @param throwError throw an error if not a server or cluster.\r\n     */\r\n    public static getNodeName(connection: Connection, throwError: boolean = false) {\r\n        if (!this.isNode(connection)) {\r\n            if (throwError) {\r\n                const message = MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.ExpectedSingleNode.message;\r\n                throw new Error(message);\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        return connection.name;\r\n    }\r\n\r\n    /**\r\n     * Gets the name of a valid node from a connection. This assumes the connection is to a single server or cluster.\r\n     *   if activeAlias is used return it, otherwise return connection.name\r\n     *\r\n     * @param connection the connection object. (should be of type server or cluster)\r\n     * @param throwError throw an error if not a server or cluster.\r\n     */\r\n    public static getValidNodeName(connection: Connection, throwError: boolean = false): string {\r\n        if (!this.isNode(connection)) {\r\n            if (throwError) {\r\n                const message = MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.ExpectedSingleNode.message;\r\n                throw new Error(message);\r\n            }\r\n\r\n            return null;\r\n        }\r\n        if (connection.activeAlias) {\r\n            return connection.activeAlias;\r\n        } else {\r\n            return connection.name;\r\n        }\r\n    }\r\n\r\n    /**\r\n     * Gets nodes of a connection of type cluster\r\n     *\r\n     * @param connection the connection object. (should be of type cluster)\r\n     * @param throwError throw an error if not a cluster.\r\n     */\r\n    public static getClusterNodes(connection: Connection, throwError: boolean = false): string[] {\r\n        if (!this.isCluster(connection)) {\r\n            if (throwError) {\r\n                const message = MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.ExpectedClusterNode.message;\r\n                throw new Error(message);\r\n            }\r\n\r\n            return [];\r\n        }\r\n\r\n        return connection.properties[connectionTypeConstants.clusterNodesProperty];\r\n    }\r\n\r\n    /**\r\n     * Gets the connection type info for a given connection\r\n     *\r\n     * @param connection the connection object.\r\n     */\r\n    public static getConnectionTypeInfo(connection: Connection): EnvironmentConnectionTypeInfo {\r\n        return EnvironmentModule.getConnectionTypeInfo(connection.type);\r\n    }\r\n\r\n    /**\r\n     * creates a connection Identifier\r\n     *\r\n     * @param connectionType the connection type.\r\n     * @param connectionName the connection name.\r\n     */\r\n    public static createConnectionId(connectionType: string, connectionName: string, groupId?: string): string {\r\n        let id = `${connectionType.toLocaleLowerCase()}!${connectionName.toLocaleLowerCase()}`;\r\n        if (groupId) {\r\n            id = id + `!${groupId.toLocaleLowerCase()}`;\r\n        }\r\n        return id;\r\n    }\r\n\r\n    /**\r\n     * Ensures tat important fields in a connection are lowercase\r\n     */\r\n    public static forceLowercase(connection: Connection): void {\r\n        connection.id = connection.id.toLocaleLowerCase();\r\n        connection.name = connection.name.toLocaleLowerCase();\r\n        connection.type = connection.type.toLocaleLowerCase();\r\n    }\r\n    /**\r\n     * Ensures tat important fields in a connection are lowercase\r\n     */\r\n    public static hasTags(connection: Connection): boolean {\r\n        return connection.tags && connection.tags.length > 0;\r\n    }\r\n\r\n    public static convertToConnectionName(inputName: string): string {\r\n        return inputName.indexOf(':') < 0 ? inputName.toLowerCase() : Net.convertIPv6ToLiteral(inputName);\r\n    }\r\n}\r\n"]}