1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Cleaning up type definitions

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-02-17 09:42:34 +03:00
parent 7e732c0da2
commit 3b5d248d08
3 changed files with 13 additions and 18 deletions

View File

@ -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<HelmChartGroups> {
public async charts(): Promise<RepoHelmChartList> {
try {
const cachedYaml = await this.cachedYaml();

View File

@ -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<string, HelmChart[]>;
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);

View File

@ -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<string, HelmChart[]>;
export type HelmChartList = Record<string, RepoHelmChartList>;
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<IHelmChartList>(endpoint())
.get<HelmChartList>(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));
});
},