mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
import { getInjectable } from "@ogre-tools/injectable";
|
|
import { apiBaseInjectionToken } from "../../api-base";
|
|
import type { RawHelmChart } from "../helm-charts.api";
|
|
import { HelmChart } from "../helm-charts.api";
|
|
import { isDefined } from "../../../utils";
|
|
|
|
export type RequestHelmCharts = () => Promise<HelmChart[]>;
|
|
export type RepoHelmChartList = Record<string, RawHelmChart[]>;
|
|
|
|
/**
|
|
* Get a list of all helm charts from all saved helm repos
|
|
*/
|
|
const requestHelmChartsInjectable = getInjectable({
|
|
id: "request-helm-charts",
|
|
instantiate: (di) => {
|
|
const apiBase = di.inject(apiBaseInjectionToken);
|
|
|
|
return async () => {
|
|
const data = await apiBase.get<Record<string, RepoHelmChartList>>("/v2/charts");
|
|
|
|
return Object
|
|
.values(data)
|
|
.reduce((allCharts, repoCharts) => allCharts.concat(Object.values(repoCharts)), new Array<RawHelmChart[]>())
|
|
.map(([chart]) => HelmChart.create(chart, { onError: "log" }))
|
|
.filter(isDefined);
|
|
};
|
|
},
|
|
});
|
|
|
|
export default requestHelmChartsInjectable;
|