Update injectable library (#4842)

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>
This commit is contained in:
Janne SavolainenandMikko Aspiala authored and GitHub committed 2022-02-25 11:10:13 -05:00
1 parent e8ca1ddf87
commit b65f6e00ec
231 files changed
+630 -613

No files matched your search

+2 -2
View File
@@ -15,7 +15,7 @@ import getCustomKubeConfigDirectoryInjectable from "../app-paths/get-custom-kube
import clusterStoreInjectable from "../cluster-store/cluster-store.injectable";
import type { ClusterModel } from "../cluster-types";
import type {
DependencyInjectionContainer,
DiContainer,
} from "@ogre-tools/injectable";
@@ -75,7 +75,7 @@ jest.mock("electron", () => ({
}));
describe("cluster-store", () => {
let mainDi: DependencyInjectionContainer;
let mainDi: DiContainer;
let clusterStore: ClusterStore;
let createCluster: (model: ClusterModel) => Cluster;
+2 -2
View File
@@ -28,7 +28,7 @@ import electron from "electron";
import { stdout, stderr } from "process";
import { getDisForUnitTesting } from "../../test-utils/get-dis-for-unit-testing";
import userStoreInjectable from "../user-store/user-store.injectable";
import type { DependencyInjectionContainer } from "@ogre-tools/injectable";
import type { DiContainer } from "@ogre-tools/injectable";
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
import type { ClusterStoreModel } from "../cluster-store/cluster-store";
import { defaultTheme } from "../vars";
@@ -37,7 +37,7 @@ console = new Console(stdout, stderr);
describe("user store tests", () => {
let userStore: UserStore;
let mainDi: DependencyInjectionContainer;
let mainDi: DiContainer;
beforeEach(async () => {
const dis = getDisForUnitTesting({ doGeneralOverrides: true });
@@ -2,12 +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 { appEventBus } from "./event-bus";
const appEventBusInjectable = getInjectable({
id: "app-event-bus",
instantiate: () => appEventBus,
lifecycle: lifecycleEnum.singleton,
});
export default appEventBusInjectable;
@@ -8,7 +8,7 @@ import { createChannel } from "../ipc-channel/create-channel/create-channel";
export type AppPaths = Record<PathName, string>;
export const appPathsInjectionToken = getInjectionToken<AppPaths>();
export const appPathsInjectionToken = getInjectionToken<AppPaths>({ id: "app-paths-token" });
export const appPathsIpcChannel = createChannel<AppPaths>("app-paths");
+3 -3
View File
@@ -2,7 +2,7 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DependencyInjectionContainer } from "@ogre-tools/injectable";
import type { DiContainer } from "@ogre-tools/injectable";
import { AppPaths, appPathsInjectionToken } from "./app-path-injection-token";
import getElectronAppPathInjectable from "../../main/app-paths/get-electron-app-path/get-electron-app-path.injectable";
import { getDisForUnitTesting } from "../../test-utils/get-dis-for-unit-testing";
@@ -13,8 +13,8 @@ import directoryForIntegrationTestingInjectable from "../../main/app-paths/direc
import path from "path";
describe("app-paths", () => {
let mainDi: DependencyInjectionContainer;
let rendererDi: DependencyInjectionContainer;
let mainDi: DiContainer;
let rendererDi: DiContainer;
let runSetups: () => Promise<void[]>;
beforeEach(() => {
@@ -2,15 +2,15 @@
* 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 path from "path";
import directoryForUserDataInjectable from "../directory-for-user-data/directory-for-user-data.injectable";
const directoryForBinariesInjectable = getInjectable({
id: "directory-for-binaries",
instantiate: (di) =>
path.join(di.inject(directoryForUserDataInjectable), "binaries"),
lifecycle: lifecycleEnum.singleton,
});
export default directoryForBinariesInjectable;
@@ -2,12 +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 { appPathsInjectionToken } from "../app-path-injection-token";
const directoryForDownloadsInjectable = getInjectable({
id: "directory-for-downloads",
instantiate: (di) => di.inject(appPathsInjectionToken).downloads,
lifecycle: lifecycleEnum.singleton,
});
export default directoryForDownloadsInjectable;
@@ -2,12 +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 { appPathsInjectionToken } from "../app-path-injection-token";
const directoryForExesInjectable = getInjectable({
id: "directory-for-exes",
instantiate: (di) => di.inject(appPathsInjectionToken).exe,
lifecycle: lifecycleEnum.singleton,
});
export default directoryForExesInjectable;
@@ -2,15 +2,15 @@
* 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 directoryForUserDataInjectable from "../directory-for-user-data/directory-for-user-data.injectable";
import path from "path";
const directoryForKubeConfigsInjectable = getInjectable({
id: "directory-for-kube-configs",
instantiate: (di) =>
path.resolve(di.inject(directoryForUserDataInjectable), "kubeconfigs"),
lifecycle: lifecycleEnum.singleton,
});
export default directoryForKubeConfigsInjectable;
@@ -2,12 +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 { appPathsInjectionToken } from "../app-path-injection-token";
const directoryForTempInjectable = getInjectable({
id: "directory-for-temp",
instantiate: (di) => di.inject(appPathsInjectionToken).temp,
lifecycle: lifecycleEnum.singleton,
});
export default directoryForTempInjectable;
@@ -2,12 +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 { appPathsInjectionToken } from "../app-path-injection-token";
const directoryForUserDataInjectable = getInjectable({
id: "directory-for-user-data",
instantiate: (di) => di.inject(appPathsInjectionToken).userData,
lifecycle: lifecycleEnum.singleton,
});
export default directoryForUserDataInjectable;
@@ -2,21 +2,21 @@
* 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 path from "path";
import directoryForKubeConfigsInjectable from "../directory-for-kube-configs/directory-for-kube-configs.injectable";
const getCustomKubeConfigDirectoryInjectable = getInjectable({
id: "get-custom-kube-config-directory",
instantiate: (di) => (directoryName: string) => {
const directoryForKubeConfigs = di.inject(directoryForKubeConfigsInjectable);
return path.resolve(
directoryForKubeConfigs,
directoryName,
);
},
lifecycle: lifecycleEnum.singleton,
});
export default getCustomKubeConfigDirectoryInjectable;
@@ -2,11 +2,13 @@
* 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 { comparer, computed } from "mobx";
import hostedClusterInjectable from "./hosted-cluster.injectable";
const allowedResourcesInjectable = getInjectable({
id: "allowed-resources",
instantiate: (di) => {
const cluster = di.inject(hostedClusterInjectable);
@@ -15,7 +17,6 @@ const allowedResourcesInjectable = getInjectable({
equals: (cur, prev) => comparer.structural(cur, prev),
});
},
lifecycle: lifecycleEnum.singleton,
});
export default allowedResourcesInjectable;
@@ -2,17 +2,17 @@
* 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 { ClusterStore } from "./cluster-store";
import { createClusterInjectionToken } from "../cluster/create-cluster-injection-token";
const clusterStoreInjectable = getInjectable({
id: "cluster-store",
instantiate: (di) =>
ClusterStore.createInstance({
createCluster: di.inject(createClusterInjectionToken),
}),
lifecycle: lifecycleEnum.singleton,
});
export default clusterStoreInjectable;
@@ -2,18 +2,18 @@
* 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 { getHostedClusterId } from "../utils";
import clusterStoreInjectable from "./cluster-store.injectable";
const hostedClusterInjectable = getInjectable({
id: "hosted-cluster",
instantiate: (di) => {
const hostedClusterId = getHostedClusterId();
return di.inject(clusterStoreInjectable).getById(hostedClusterId);
},
lifecycle: lifecycleEnum.singleton,
});
export default hostedClusterInjectable;
@@ -5,7 +5,7 @@
import { AuthorizationV1Api, KubeConfig, V1ResourceAttributes } from "@kubernetes/client-node";
import logger from "../logger";
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
export type CanI = (resourceAttributes: V1ResourceAttributes) => Promise<boolean>;
@@ -38,8 +38,8 @@ export function authorizationReview(proxyConfig: KubeConfig): CanI {
}
const authorizationReviewInjectable = getInjectable({
id: "authorization-review",
instantiate: () => authorizationReview,
lifecycle: lifecycleEnum.singleton,
});
export default authorizationReviewInjectable;
@@ -7,4 +7,4 @@ import type { ClusterModel } from "../cluster-types";
import type { Cluster } from "./cluster";
export const createClusterInjectionToken =
getInjectionToken<(model: ClusterModel) => Cluster>();
getInjectionToken<(model: ClusterModel) => Cluster>({ id: "create-cluster-token" });
@@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { CoreV1Api, KubeConfig } from "@kubernetes/client-node";
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
export type ListNamespaces = () => Promise<string[]>;
@@ -18,8 +18,8 @@ export function listNamespaces(config: KubeConfig): ListNamespaces {
}
const listNamespacesInjectable = getInjectable({
id: "list-namespaces",
instantiate: () => listNamespaces,
lifecycle: lifecycleEnum.singleton,
});
export default listNamespacesInjectable;
@@ -2,18 +2,18 @@
* 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 path from "path";
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
const directoryForLensLocalStorageInjectable = getInjectable({
id: "directory-for-lens-local-storage",
instantiate: (di) =>
path.resolve(
di.inject(directoryForUserDataInjectable),
"lens-local-storage",
),
lifecycle: lifecycleEnum.singleton,
});
export default directoryForLensLocalStorageInjectable;
+2 -2
View File
@@ -2,13 +2,13 @@
* 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 fse from "fs-extra";
const fsInjectable = getInjectable({
id: "fs",
instantiate: () => fse,
causesSideEffects: true,
lifecycle: lifecycleEnum.singleton,
});
export default fsInjectable;
+2 -2
View File
@@ -2,12 +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 fsInjectable from "./fs.injectable";
const readDirInjectable = getInjectable({
id: "read-dir",
instantiate: (di) => di.inject(fsInjectable).readdir,
lifecycle: lifecycleEnum.singleton,
});
export default readDirInjectable;
+2 -2
View File
@@ -2,12 +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 fsInjectable from "./fs.injectable";
const readFileInjectable = getInjectable({
id: "read-file",
instantiate: (di) => di.inject(fsInjectable).readFile,
lifecycle: lifecycleEnum.singleton,
});
export default readFileInjectable;
+2 -2
View File
@@ -2,12 +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 fsInjectable from "./fs.injectable";
const readJsonFileInjectable = getInjectable({
id: "read-json-file",
instantiate: (di) => di.inject(fsInjectable).readJson,
lifecycle: lifecycleEnum.singleton,
});
export default readJsonFileInjectable;
+3 -3
View File
@@ -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 type { EnsureOptions, WriteOptions } from "fs-extra";
import path from "path";
import type { JsonValue } from "type-fest";
@@ -23,6 +23,8 @@ const writeJsonFile = ({ writeJson, ensureDir }: Dependencies) => async (filePat
};
const writeJsonFileInjectable = getInjectable({
id: "write-json-file",
instantiate: (di) => {
const { writeJson, ensureDir } = di.inject(fsInjectable);
@@ -31,8 +33,6 @@ const writeJsonFileInjectable = getInjectable({
ensureDir,
});
},
lifecycle: lifecycleEnum.singleton,
});
export default writeJsonFileInjectable;
+2 -2
View File
@@ -2,12 +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 { HotbarStore } from "./hotbar-store";
const hotbarManagerInjectable = getInjectable({
id: "hotbar-manager",
instantiate: () => HotbarStore.getInstance(),
lifecycle: lifecycleEnum.singleton,
});
export default hotbarManagerInjectable;
@@ -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 { UserStore } from "./user-store";
const userStoreInjectable = getInjectable({
id: "user-store",
instantiate: () => UserStore.createInstance(),
lifecycle: lifecycleEnum.singleton,
});
export default userStoreInjectable;
@@ -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 allowedResourcesInjectable from "../cluster-store/allowed-resources.injectable";
import type { KubeResource } from "../rbac";
@@ -10,13 +10,13 @@ export type IsAllowedResource = (resource: KubeResource) => boolean;
// TODO: This injectable obscures MobX de-referencing. Make it more apparent in usage.
const isAllowedResourceInjectable = getInjectable({
id: "is-allowed-resource",
instantiate: (di) => {
const allowedResources = di.inject(allowedResourcesInjectable);
return (resource: KubeResource) => allowedResources.get().has(resource);
},
lifecycle: lifecycleEnum.singleton,
});
export default isAllowedResourceInjectable;
+2 -2
View File
@@ -2,12 +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 { isLinux } from "../vars";
const isLinuxInjectable = getInjectable({
id: "is-linux",
instantiate: () => isLinux,
lifecycle: lifecycleEnum.singleton,
});
export default isLinuxInjectable;
+2 -2
View File
@@ -2,12 +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 { isWindows } from "../vars";
const isWindowsInjectable = getInjectable({
id: "is-windows",
instantiate: () => isWindows,
lifecycle: lifecycleEnum.singleton,
});
export default isWindowsInjectable;