mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Adapt to new typing in injectable
Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
parent
35f363fdd3
commit
ca086350ad
@ -2,13 +2,12 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { baseBinariesDir } from "../../vars";
|
||||
|
||||
const directoryForBundledBinariesInjectable = getInjectable({
|
||||
id: "directory-for-bundled-binaries",
|
||||
instantiate: () => baseBinariesDir.get(),
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
export default directoryForBundledBinariesInjectable;
|
||||
|
||||
@ -2,13 +2,12 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { contextDir } from "../vars";
|
||||
|
||||
const contextDirInjectable = getInjectable({
|
||||
id: "context-dir",
|
||||
instantiate: () => contextDir,
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
export default contextDirInjectable;
|
||||
|
||||
@ -2,13 +2,12 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { isDevelopment } from "../vars";
|
||||
|
||||
const isDevelopmentInjectable = getInjectable({
|
||||
id: "is-development",
|
||||
instantiate: () => isDevelopment,
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
export default isDevelopmentInjectable;
|
||||
|
||||
@ -2,29 +2,19 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { Injectable, TentativeTuple } from "@ogre-tools/injectable";
|
||||
|
||||
import { getLegacyGlobalDiForExtensionApi } from "./legacy-global-di-for-extension-api";
|
||||
import type { Inject } from "@ogre-tools/injectable";
|
||||
|
||||
type FactoryType = <
|
||||
TInjectable extends Injectable<unknown, TInstance, TInstantiationParameter>,
|
||||
TInstantiationParameter,
|
||||
TInstance extends (...args: unknown[]) => any,
|
||||
TFunction extends (...args: unknown[]) => any = Awaited<
|
||||
ReturnType<TInjectable["instantiate"]>
|
||||
>,
|
||||
>(
|
||||
injectableKey: TInjectable,
|
||||
...instantiationParameter: TentativeTuple<TInstantiationParameter>
|
||||
) => (...args: Parameters<TFunction>) => ReturnType<TFunction>;
|
||||
export const asLegacyGlobalFunctionForExtensionApi = ((
|
||||
injectableKey,
|
||||
instantiationParameter,
|
||||
) =>
|
||||
(...args: any[]) => {
|
||||
const injected = getLegacyGlobalDiForExtensionApi().inject(
|
||||
injectableKey,
|
||||
instantiationParameter,
|
||||
) as unknown as (...args: any[]) => any;
|
||||
|
||||
export const asLegacyGlobalFunctionForExtensionApi: FactoryType =
|
||||
(injectableKey, ...instantiationParameter) =>
|
||||
(...args) => {
|
||||
const injected = getLegacyGlobalDiForExtensionApi().inject(
|
||||
injectableKey,
|
||||
...instantiationParameter,
|
||||
);
|
||||
|
||||
return injected(...args);
|
||||
};
|
||||
return injected(...args);
|
||||
}) as Inject<false>;
|
||||
|
||||
@ -2,44 +2,15 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { Injectable, TentativeTuple } from "@ogre-tools/injectable";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "./legacy-global-di-for-extension-api";
|
||||
|
||||
type MapInjectables<T> = {
|
||||
[Key in keyof T]: T[Key] extends () => infer Res ? Res : never;
|
||||
};
|
||||
import { asLegacyGlobalForExtensionApi } from "./as-legacy-global-object-for-extension-api";
|
||||
import type { Injectable } from "@ogre-tools/injectable";
|
||||
|
||||
export const asLegacyGlobalObjectForExtensionApiWithModifications = <
|
||||
TInjectable extends Injectable<unknown, unknown, TInstantiationParameter>,
|
||||
TInstantiationParameter,
|
||||
OtherFields extends Record<string, () => any>,
|
||||
InjectableInstance extends InjectionTokenInstance,
|
||||
InjectionTokenInstance,
|
||||
ModificationObject extends object,
|
||||
>(
|
||||
injectableKey: TInjectable,
|
||||
otherFields: OtherFields,
|
||||
...instantiationParameter: TentativeTuple<TInstantiationParameter>
|
||||
injectable: Injectable<InjectableInstance, InjectionTokenInstance, void>,
|
||||
modificationObject: ModificationObject,
|
||||
) =>
|
||||
new Proxy(
|
||||
{},
|
||||
{
|
||||
get(target, propertyName) {
|
||||
if (propertyName === "$$typeof") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const instance: any = getLegacyGlobalDiForExtensionApi().inject(
|
||||
injectableKey,
|
||||
...instantiationParameter,
|
||||
);
|
||||
|
||||
const propertyValue = instance[propertyName] ?? otherFields[propertyName as any]();
|
||||
|
||||
if (typeof propertyValue === "function") {
|
||||
return function (...args: any[]) {
|
||||
return propertyValue.apply(instance, args);
|
||||
};
|
||||
}
|
||||
|
||||
return propertyValue;
|
||||
},
|
||||
},
|
||||
) as ReturnType<TInjectable["instantiate"]> & MapInjectables<OtherFields>;
|
||||
Object.assign(modificationObject, asLegacyGlobalForExtensionApi(injectable));
|
||||
|
||||
@ -2,27 +2,34 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { Injectable, TentativeTuple } from "@ogre-tools/injectable";
|
||||
import type { Inject } from "@ogre-tools/injectable";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "./legacy-global-di-for-extension-api";
|
||||
|
||||
export const asLegacyGlobalObjectForExtensionApi = <
|
||||
TInjectable extends Injectable<unknown, unknown, TInstantiationParameter>,
|
||||
TInstantiationParameter,
|
||||
>(
|
||||
injectableKey: TInjectable,
|
||||
...instantiationParameter: TentativeTuple<TInstantiationParameter>
|
||||
) =>
|
||||
export const asLegacyGlobalForExtensionApi = ((
|
||||
injectable,
|
||||
instantiationParameter,
|
||||
) =>
|
||||
new Proxy(
|
||||
{},
|
||||
|
||||
{
|
||||
apply(target, thisArg, argArray) {
|
||||
const fn = getLegacyGlobalDiForExtensionApi().inject(
|
||||
injectable,
|
||||
instantiationParameter,
|
||||
) as unknown as (...args: any[]) => any;
|
||||
|
||||
return fn(...argArray);
|
||||
},
|
||||
|
||||
get(target, propertyName) {
|
||||
if (propertyName === "$$typeof") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const instance: any = getLegacyGlobalDiForExtensionApi().inject(
|
||||
injectableKey,
|
||||
...instantiationParameter,
|
||||
injectable,
|
||||
instantiationParameter,
|
||||
);
|
||||
|
||||
const propertyValue = instance[propertyName];
|
||||
@ -36,4 +43,4 @@ export const asLegacyGlobalObjectForExtensionApi = <
|
||||
return propertyValue;
|
||||
},
|
||||
},
|
||||
) as ReturnType<TInjectable["instantiate"]>;
|
||||
)) as Inject<false>;
|
||||
|
||||
@ -5,16 +5,16 @@
|
||||
import { asLegacyGlobalFunctionForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
|
||||
import createTerminalTabInjectable from "../../renderer/components/dock/terminal/create-terminal-tab.injectable";
|
||||
import terminalStoreInjectable from "../../renderer/components/dock/terminal/store.injectable";
|
||||
import { asLegacyGlobalObjectForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
import { asLegacyGlobalForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
import logTabStoreInjectable from "../../renderer/components/dock/logs/tab-store.injectable";
|
||||
|
||||
import commandOverlayInjectable from "../../renderer/components/command-palette/command-overlay.injectable";
|
||||
import { asLegacyGlobalObjectForExtensionApiWithModifications } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api-with-modifications";
|
||||
import createPodLogsTabInjectable from "../../renderer/components/dock/logs/create-pod-logs-tab.injectable";
|
||||
import createWorkloadLogsTabInjectable from "../../renderer/components/dock/logs/create-workload-logs-tab.injectable";
|
||||
import sendCommandInjectable from "../../renderer/components/dock/terminal/send-command.injectable";
|
||||
import { podsStore } from "../../renderer/components/+workloads-pods/pods.store";
|
||||
import renameTabInjectable from "../../renderer/components/dock/dock/rename-tab.injectable";
|
||||
import { asLegacyGlobalObjectForExtensionApiWithModifications } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api-with-modifications";
|
||||
|
||||
// layouts
|
||||
export * from "../../renderer/components/layout/main-layout";
|
||||
@ -33,7 +33,9 @@ export * from "../../renderer/components/switch";
|
||||
export * from "../../renderer/components/input/input";
|
||||
|
||||
// command-overlay
|
||||
export const CommandOverlay = asLegacyGlobalObjectForExtensionApi(commandOverlayInjectable);
|
||||
export const CommandOverlay = asLegacyGlobalForExtensionApi(
|
||||
commandOverlayInjectable,
|
||||
);
|
||||
|
||||
export type {
|
||||
CategoryColumnRegistration,
|
||||
@ -74,30 +76,52 @@ export * from "../../renderer/components/+events/kube-event-details";
|
||||
// specific exports
|
||||
export * from "../../renderer/components/status-brick";
|
||||
|
||||
export const createTerminalTab = asLegacyGlobalFunctionForExtensionApi(createTerminalTabInjectable);
|
||||
export const terminalStore = asLegacyGlobalObjectForExtensionApiWithModifications(terminalStoreInjectable, {
|
||||
sendCommand: () => asLegacyGlobalFunctionForExtensionApi(sendCommandInjectable),
|
||||
});
|
||||
export const logTabStore = asLegacyGlobalObjectForExtensionApiWithModifications(logTabStoreInjectable, {
|
||||
createPodTab: () => asLegacyGlobalFunctionForExtensionApi(createPodLogsTabInjectable),
|
||||
createWorkloadTab: () => asLegacyGlobalFunctionForExtensionApi(createWorkloadLogsTabInjectable),
|
||||
renameTab: () => (tabId: string): void => {
|
||||
const renameTab = asLegacyGlobalFunctionForExtensionApi(renameTabInjectable);
|
||||
const tabData = logTabStore.getData(tabId);
|
||||
const pod = podsStore.getById(tabData.selectedPodId);
|
||||
export const createTerminalTab = asLegacyGlobalFunctionForExtensionApi(
|
||||
createTerminalTabInjectable,
|
||||
);
|
||||
|
||||
renameTab(tabId, `Pod ${pod.getName()}`);
|
||||
export const terminalStore =
|
||||
asLegacyGlobalObjectForExtensionApiWithModifications(
|
||||
terminalStoreInjectable,
|
||||
{
|
||||
sendCommand: asLegacyGlobalFunctionForExtensionApi(sendCommandInjectable),
|
||||
},
|
||||
);
|
||||
|
||||
export const logTabStore = asLegacyGlobalObjectForExtensionApiWithModifications(
|
||||
logTabStoreInjectable,
|
||||
{
|
||||
createPodTab: asLegacyGlobalFunctionForExtensionApi(
|
||||
createPodLogsTabInjectable,
|
||||
),
|
||||
|
||||
createWorkloadTab: asLegacyGlobalFunctionForExtensionApi(
|
||||
createWorkloadLogsTabInjectable,
|
||||
),
|
||||
|
||||
renameTab: (tabId: string): void => {
|
||||
const renameTab =
|
||||
asLegacyGlobalFunctionForExtensionApi(renameTabInjectable);
|
||||
|
||||
const tabData = logTabStore.getData(tabId);
|
||||
const pod = podsStore.getById(tabData.selectedPodId);
|
||||
|
||||
renameTab(tabId, `Pod ${pod.getName()}`);
|
||||
},
|
||||
|
||||
tabs: undefined,
|
||||
},
|
||||
tabs: () => undefined,
|
||||
});
|
||||
);
|
||||
|
||||
export class TerminalStore {
|
||||
static getInstance() {
|
||||
return terminalStore;
|
||||
}
|
||||
|
||||
static createInstance() {
|
||||
return terminalStore;
|
||||
}
|
||||
|
||||
static resetInstance() {
|
||||
console.warn("TerminalStore.resetInstance() does nothing");
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import mainExtensionsInjectable from "../../../extensions/main-extensions.injectable";
|
||||
import { terminalShellEnvModify } from "./terminal-shell-env-modifiers";
|
||||
|
||||
@ -14,8 +14,6 @@ const terminalShellEnvModifyInjectable = getInjectable({
|
||||
terminalShellEnvModify({
|
||||
extensions: di.inject(mainExtensionsInjectable),
|
||||
}),
|
||||
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
export default terminalShellEnvModifyInjectable;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computed } from "mobx";
|
||||
import rendererExtensionsInjectable from "../../../extensions/renderer-extensions.injectable";
|
||||
import { OverviewStatuses } from "./overview-statuses";
|
||||
@ -31,8 +31,6 @@ const detailComponentsInjectable = getInjectable({
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
const coreRegistrations = [
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computed } from "mobx";
|
||||
import rendererExtensionsInjectable from "../../../extensions/renderer-extensions.injectable";
|
||||
|
||||
@ -16,8 +16,6 @@ const statusRegistrationsInjectable = getInjectable({
|
||||
extensions.get().flatMap((extension) => extension.kubeObjectStatusTexts),
|
||||
);
|
||||
},
|
||||
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
export default statusRegistrationsInjectable;
|
||||
|
||||
@ -3,9 +3,12 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import React from "react";
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computed, IComputedValue } from "mobx";
|
||||
import type { StatusBarItemProps, StatusBarRegistration } from "./status-bar-registration";
|
||||
import type {
|
||||
StatusBarItemProps,
|
||||
StatusBarRegistration,
|
||||
} from "./status-bar-registration";
|
||||
import statusBarItemsInjectable from "./status-bar-items.injectable";
|
||||
|
||||
export interface RegisteredStatusBarItems {
|
||||
@ -69,7 +72,6 @@ const registeredStatusBarItemsInjectable = getInjectable({
|
||||
registrations: di.inject(statusBarItemsInjectable),
|
||||
}),
|
||||
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
export default registeredStatusBarItemsInjectable;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computed } from "mobx";
|
||||
import rendererExtensionsInjectable from "../../../extensions/renderer-extensions.injectable";
|
||||
|
||||
@ -12,12 +12,10 @@ const statusBarItemsInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
const extensions = di.inject(rendererExtensionsInjectable);
|
||||
|
||||
return computed(() => (
|
||||
extensions.get()
|
||||
.flatMap(ext => ext.statusBarItems)
|
||||
));
|
||||
return computed(() =>
|
||||
extensions.get().flatMap((ext) => ext.statusBarItems),
|
||||
);
|
||||
},
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
export default statusBarItemsInjectable;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user