From 3b5d248d08de36891246e1d35c1c327f9e3456e8 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Wed, 17 Feb 2021 09:42:34 +0300 Subject: [PATCH] Cleaning up type definitions Signed-off-by: Alex Andreev --- src/main/helm/helm-chart-manager.ts | 8 +++----- src/main/helm/helm-service.ts | 12 ++++++------ src/renderer/api/endpoints/helm-charts.api.ts | 11 ++++------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/main/helm/helm-chart-manager.ts b/src/main/helm/helm-chart-manager.ts index cf6832a91a..ee11b980d3 100644 --- a/src/main/helm/helm-chart-manager.ts +++ b/src/main/helm/helm-chart-manager.ts @@ -4,12 +4,10 @@ import { HelmRepo, HelmRepoManager } from "./helm-repo-manager"; import logger from "../logger"; import { promiseExec } from "../promise-exec"; import { helmCli } from "./helm-cli"; -import { HelmChart } from "../../renderer/api/endpoints/helm-charts.api"; - -export type HelmChartGroups = { [key: string]: HelmChart[] }; +import type { RepoHelmChartList } from "../../renderer/api/endpoints/helm-charts.api"; type CachedYaml = { - entries: HelmChartGroups + entries: RepoHelmChartList }; export class HelmChartManager { @@ -27,7 +25,7 @@ export class HelmChartManager { return charts[name]; } - public async charts(): Promise { + public async charts(): Promise { try { const cachedYaml = await this.cachedYaml(); diff --git a/src/main/helm/helm-service.ts b/src/main/helm/helm-service.ts index c92a864acd..8e388a6e12 100644 --- a/src/main/helm/helm-service.ts +++ b/src/main/helm/helm-service.ts @@ -5,7 +5,7 @@ import { HelmChartManager } from "./helm-chart-manager"; import { releaseManager } from "./helm-release-manager"; import { HelmChart } from "../../renderer/api/endpoints/helm-charts.api"; -import type { HelmChartGroups } from "./helm-chart-manager"; +import type { HelmChartList, RepoHelmChartList } from "../../renderer/api/endpoints/helm-charts.api"; class HelmService { public async installChart(cluster: Cluster, data: { chart: string; values: {}; name: string; namespace: string; version: string }) { @@ -13,7 +13,7 @@ class HelmService { } public async listCharts() { - const charts: any = {}; + const charts: HelmChartList = {}; await repoManager.init(); const repositories = await repoManager.repositories(); @@ -21,7 +21,7 @@ class HelmService { for (const repo of repositories) { charts[repo.name] = {}; const manager = new HelmChartManager(repo); - const { groups } = new ChartGroups(await manager.charts()); + const { groups } = new HelmChartGroups(await manager.charts()); charts[repo.name] = groups; } @@ -95,15 +95,15 @@ class HelmService { } } -class ChartGroups { +class HelmChartGroups { private items: Map; - constructor(groups: HelmChartGroups) { + constructor(groups: RepoHelmChartList) { this.items = new Map(Object.entries(groups)); this.excludeDeprecatedGroups(); } - excludeDeprecatedGroups() { + private excludeDeprecatedGroups() { for (const [chartName, charts] of this.items) { if (charts[0].deprecated) { this.items.delete(chartName); diff --git a/src/renderer/api/endpoints/helm-charts.api.ts b/src/renderer/api/endpoints/helm-charts.api.ts index 7b097ea373..02b5b0dbee 100644 --- a/src/renderer/api/endpoints/helm-charts.api.ts +++ b/src/renderer/api/endpoints/helm-charts.api.ts @@ -3,11 +3,8 @@ import { apiBase } from "../index"; import { stringify } from "querystring"; import { autobind } from "../../utils"; -interface IHelmChartList { - [repo: string]: { - [name: string]: HelmChart[]; - }; -} +export type RepoHelmChartList = Record; +export type HelmChartList = Record; export interface IHelmChartDetails { readme: string; @@ -22,12 +19,12 @@ const endpoint = compile(`/v2/charts/:repo?/:name?`) as (params?: { export const helmChartsApi = { list() { return apiBase - .get(endpoint()) + .get(endpoint()) .then(data => { return Object .values(data) .reduce((allCharts, repoCharts) => allCharts.concat(Object.values(repoCharts)), []) - .map((charts: HelmChart[]) => HelmChart.create(charts[0])); + .map(([chart]) => HelmChart.create(chart)); }); },