From e10caaf8f4da67d80e85bd487fd28b0530272384 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Mon, 16 Jan 2023 09:47:31 -0500 Subject: [PATCH] Fix extension API - Make sure that dependency constructors are not exported - Readd `KubeJsonApi.forCluster` Signed-off-by: Sebastian Malton --- src/extensions/common-api/k8s-api.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/extensions/common-api/k8s-api.ts b/src/extensions/common-api/k8s-api.ts index c24f7d14e3f5..3150c920f672 100644 --- a/src/extensions/common-api/k8s-api.ts +++ b/src/extensions/common-api/k8s-api.ts @@ -27,6 +27,10 @@ import { getLegacyGlobalDiForExtensionApi } from "../as-legacy-globals-for-exten import maybeKubeApiInjectable from "../../common/k8s-api/maybe-kube-api.injectable"; import { DeploymentApi as InternalDeploymentApi, IngressApi as InternalIngressApi, NodeApi, PersistentVolumeClaimApi, PodApi } from "../../common/k8s-api/endpoints"; import { storesAndApisCanBeCreatedInjectionToken } from "../../common/k8s-api/stores-apis-can-be-created.token"; +import type { JsonApiConfig } from "../../common/k8s-api/json-api"; +import type { KubeJsonApi as InternalKubeJsonApi } from "../../common/k8s-api/kube-json-api"; +import createKubeJsonApiInjectable from "../../common/k8s-api/create-kube-json-api.injectable"; +import type { RequestInit } from "node-fetch"; export const apiManager = asLegacyGlobalForExtensionApi(apiManagerInjectable); export const forCluster = asLegacyGlobalFunctionForExtensionApi(createKubeApiForClusterInjectable); @@ -107,11 +111,24 @@ export { type KubeStatusData, } from "../../common/k8s-api/kube-object"; -export { - KubeJsonApi, - type KubeJsonApiData, +export type { + KubeJsonApiData, } from "../../common/k8s-api/kube-json-api"; +function KubeJsonApiCstr(config: JsonApiConfig, reqInit?: RequestInit) { + const di = getLegacyGlobalDiForExtensionApi(); + const createKubeJsonApi = di.inject(createKubeJsonApiInjectable); + + return createKubeJsonApi(config, reqInit); +} + +export const KubeJsonApi = Object.assign( + KubeJsonApiCstr as unknown as new (config: JsonApiConfig, reqInit?: RequestInit) => InternalKubeJsonApi, + { + forCluster, + }, +); + export abstract class KubeObjectStore< K extends KubeObject = KubeObject, A extends InternalKubeApi = InternalKubeApi>,