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

fix typings

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2022-03-03 18:50:04 +02:00
parent f59bdec9a9
commit b3b3ad6a4c

View File

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