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

loosen api-manager kubeobject types

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2022-03-03 11:39:24 +02:00
parent d72ebac5f3
commit 44cd91053e

View File

@ -12,15 +12,15 @@ import type { KubeObject } from "./kube-object";
import { IKubeObjectRef, parseKubeApi, createKubeApiURL } from "./kube-api-parse"; import { IKubeObjectRef, parseKubeApi, createKubeApiURL } from "./kube-api-parse";
export class ApiManager { export class ApiManager {
private apis = observable.map<string, KubeApi<KubeObject>>(); private apis = observable.map<string, KubeApi<any>>();
private stores = observable.map<string, KubeObjectStore<KubeObject>>(); private stores = observable.map<string, KubeObjectStore<any>>();
constructor() { constructor() {
makeObservable(this); makeObservable(this);
autoBind(this); autoBind(this);
} }
getApi(pathOrCallback: string | ((api: KubeApi<KubeObject>) => boolean)) { getApi(pathOrCallback: string | ((api: KubeApi<any>) => boolean)) {
if (typeof pathOrCallback === "string") { if (typeof pathOrCallback === "string") {
return this.apis.get(pathOrCallback) || this.apis.get(parseKubeApi(pathOrCallback).apiBase); return this.apis.get(pathOrCallback) || this.apis.get(parseKubeApi(pathOrCallback).apiBase);
} }
@ -32,7 +32,7 @@ export class ApiManager {
return iter.find(this.apis.values(), api => api.kind === kind && api.apiVersionWithGroup === apiVersion); return iter.find(this.apis.values(), api => api.kind === kind && api.apiVersionWithGroup === apiVersion);
} }
registerApi(apiBase: string, api: KubeApi<KubeObject>) { registerApi(apiBase: string, api: KubeApi<any>) {
if (!api.apiBase) return; if (!api.apiBase) return;
if (!this.apis.has(apiBase)) { if (!this.apis.has(apiBase)) {
@ -58,7 +58,7 @@ export class ApiManager {
return api; return api;
} }
unregisterApi(api: string | KubeApi<KubeObject>) { unregisterApi(api: string | KubeApi<any>) {
if (typeof api === "string") this.apis.delete(api); if (typeof api === "string") this.apis.delete(api);
else { else {
const apis = Array.from(this.apis.entries()); const apis = Array.from(this.apis.entries());
@ -69,17 +69,17 @@ export class ApiManager {
} }
@action @action
registerStore(store: KubeObjectStore<KubeObject>, apis: KubeApi<KubeObject>[] = [store.api]) { registerStore(store: KubeObjectStore<any>, apis: KubeApi<any>[] = [store.api]) {
apis.filter(Boolean).forEach(api => { apis.filter(Boolean).forEach(api => {
if (api.apiBase) this.stores.set(api.apiBase, store); if (api.apiBase) this.stores.set(api.apiBase, store);
}); });
} }
getStore<S extends KubeObjectStore<KubeObject>>(api: string | KubeApi<KubeObject>): S | undefined { getStore<S extends KubeObjectStore<any>>(api: string | KubeApi<KubeObject>): S | undefined {
return this.stores.get(this.resolveApi(api)?.apiBase) as S; return this.stores.get(this.resolveApi(api)?.apiBase) as S;
} }
lookupApiLink(ref: IKubeObjectRef, parentObject?: KubeObject): string { lookupApiLink<T extends KubeObject = KubeObject>(ref: IKubeObjectRef, parentObject?: T): string {
const { const {
kind, apiVersion, name, kind, apiVersion, name,
namespace = parentObject?.getNs(), namespace = parentObject?.getNs(),