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 logger from "../logger";
import { promiseExec } from "../promise-exec"; import { promiseExec } from "../promise-exec";
import { helmCli } from "./helm-cli"; import { helmCli } from "./helm-cli";
import { HelmChart } from "../../renderer/api/endpoints/helm-charts.api"; import type { RepoHelmChartList } from "../../renderer/api/endpoints/helm-charts.api";
export type HelmChartGroups = { [key: string]: HelmChart[] };
type CachedYaml = { type CachedYaml = {
entries: HelmChartGroups entries: RepoHelmChartList
}; };
export class HelmChartManager { export class HelmChartManager {
@ -27,7 +25,7 @@ export class HelmChartManager {
return charts[name]; return charts[name];
} }
public async charts(): Promise<HelmChartGroups> { public async charts(): Promise<RepoHelmChartList> {
try { try {
const cachedYaml = await this.cachedYaml(); const cachedYaml = await this.cachedYaml();

View File

@ -5,7 +5,7 @@ import { HelmChartManager } from "./helm-chart-manager";
import { releaseManager } from "./helm-release-manager"; import { releaseManager } from "./helm-release-manager";
import { HelmChart } from "../../renderer/api/endpoints/helm-charts.api"; 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 { class HelmService {
public async installChart(cluster: Cluster, data: { chart: string; values: {}; name: string; namespace: string; version: string }) { public async installChart(cluster: Cluster, data: { chart: string; values: {}; name: string; namespace: string; version: string }) {
@ -13,7 +13,7 @@ class HelmService {
} }
public async listCharts() { public async listCharts() {
const charts: any = {}; const charts: HelmChartList = {};
await repoManager.init(); await repoManager.init();
const repositories = await repoManager.repositories(); const repositories = await repoManager.repositories();
@ -21,7 +21,7 @@ class HelmService {
for (const repo of repositories) { for (const repo of repositories) {
charts[repo.name] = {}; charts[repo.name] = {};
const manager = new HelmChartManager(repo); const manager = new HelmChartManager(repo);
const { groups } = new ChartGroups(await manager.charts()); const { groups } = new HelmChartGroups(await manager.charts());
charts[repo.name] = groups; charts[repo.name] = groups;
} }
@ -95,15 +95,15 @@ class HelmService {
} }
} }
class ChartGroups { class HelmChartGroups {
private items: Map<string, HelmChart[]>; private items: Map<string, HelmChart[]>;
constructor(groups: HelmChartGroups) { constructor(groups: RepoHelmChartList) {
this.items = new Map(Object.entries(groups)); this.items = new Map(Object.entries(groups));
this.excludeDeprecatedGroups(); this.excludeDeprecatedGroups();
} }
excludeDeprecatedGroups() { private excludeDeprecatedGroups() {
for (const [chartName, charts] of this.items) { for (const [chartName, charts] of this.items) {
if (charts[0].deprecated) { if (charts[0].deprecated) {
this.items.delete(chartName); this.items.delete(chartName);

View File

@ -3,11 +3,8 @@ import { apiBase } from "../index";
import { stringify } from "querystring"; import { stringify } from "querystring";
import { autobind } from "../../utils"; import { autobind } from "../../utils";
interface IHelmChartList { export type RepoHelmChartList = Record<string, HelmChart[]>;
[repo: string]: { export type HelmChartList = Record<string, RepoHelmChartList>;
[name: string]: HelmChart[];
};
}
export interface IHelmChartDetails { export interface IHelmChartDetails {
readme: string; readme: string;
@ -22,12 +19,12 @@ const endpoint = compile(`/v2/charts/:repo?/:name?`) as (params?: {
export const helmChartsApi = { export const helmChartsApi = {
list() { list() {
return apiBase return apiBase
.get<IHelmChartList>(endpoint()) .get<HelmChartList>(endpoint())
.then(data => { .then(data => {
return Object return Object
.values(data) .values(data)
.reduce((allCharts, repoCharts) => allCharts.concat(Object.values(repoCharts)), []) .reduce((allCharts, repoCharts) => allCharts.concat(Object.values(repoCharts)), [])
.map((charts: HelmChart[]) => HelmChart.create(charts[0])); .map(([chart]) => HelmChart.create(chart));
}); });
}, },