mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add better type safety around Channels (#6133)
* Add better type safety around Channels - Reallow non-JSON serializable complex types - Remove unnecessary JSON serialization step to IPC - Remove unnecesary injectable-ization of MessageChannel and RequestChannel declarations - Add channel listener injectable getter function to remove general need for type casting and improve type safety Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add check to verify data in IPC related tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix implementation in light of new safety check in tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix listener ID clash potential Signed-off-by: Sebastian Malton <sebastian@malton.name> * Switch to not forcing split of request channel handlers being seperate from the listener decl Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move message channels to changed signature too Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix not registering listener Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix test imports Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Refactor listening of different channel kinds Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add test covering new checking code for request channel handlers Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
d96918c966
commit
5a5eda935b
115 files changed
+949
-1568
No files matched your search
@@ -6,9 +6,8 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import execFileInjectable from "../../../common/fs/exec-file.injectable";
|
||||
import helmBinaryPathInjectable from "../helm-binary-path.injectable";
|
||||
import type { AsyncResult } from "../../../common/utils/async-result";
|
||||
import { getErrorMessage } from "../../../common/utils/get-error-message";
|
||||
|
||||
export type ExecHelm = (args: string[]) => Promise<AsyncResult<string>>;
|
||||
export type ExecHelm = (args: string[]) => Promise<AsyncResult<string, string>>;
|
||||
|
||||
const execHelmInjectable = getInjectable({
|
||||
id: "exec-helm",
|
||||
@@ -18,15 +17,18 @@ const execHelmInjectable = getInjectable({
|
||||
const helmBinaryPath = di.inject(helmBinaryPathInjectable);
|
||||
|
||||
return async (args) => {
|
||||
try {
|
||||
const response = await execFile(helmBinaryPath, args, {
|
||||
maxBuffer: 32 * 1024 * 1024 * 1024, // 32 MiB
|
||||
});
|
||||
const response = await execFile(helmBinaryPath, args, {
|
||||
maxBuffer: 32 * 1024 * 1024 * 1024, // 32 MiB
|
||||
});
|
||||
|
||||
return { callWasSuccessful: true, response };
|
||||
} catch (error) {
|
||||
return { callWasSuccessful: false, error: getErrorMessage(error) };
|
||||
if (response.callWasSuccessful) {
|
||||
return response;
|
||||
}
|
||||
|
||||
return {
|
||||
callWasSuccessful: false,
|
||||
error: response.error.stderr || response.error.error.message,
|
||||
};
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
+5
-17
@@ -2,25 +2,13 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import addHelmRepositoryChannelInjectable from "../../../../common/helm/add-helm-repository-channel.injectable";
|
||||
import { addHelmRepositoryChannel } from "../../../../common/helm/add-helm-repository-channel";
|
||||
import { getRequestChannelListenerInjectable } from "../../../utils/channel/channel-listeners/listener-tokens";
|
||||
import addHelmRepositoryInjectable from "./add-helm-repository.injectable";
|
||||
import { requestChannelListenerInjectionToken } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
|
||||
const addHelmRepositoryChannelListenerInjectable = getInjectable({
|
||||
id: "add-helm-repository-channel-listener",
|
||||
|
||||
instantiate: (di) => {
|
||||
const addHelmRepository = di.inject(addHelmRepositoryInjectable);
|
||||
const channel = di.inject(addHelmRepositoryChannelInjectable);
|
||||
|
||||
return {
|
||||
channel,
|
||||
handler: addHelmRepository,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: requestChannelListenerInjectionToken,
|
||||
const addHelmRepositoryChannelListenerInjectable = getRequestChannelListenerInjectable({
|
||||
channel: addHelmRepositoryChannel,
|
||||
handler: (di) => di.inject(addHelmRepositoryInjectable),
|
||||
});
|
||||
|
||||
export default addHelmRepositoryChannelListenerInjectable;
|
||||
+5
-17
@@ -2,25 +2,13 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { requestChannelListenerInjectionToken } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
import getActiveHelmRepositoriesChannelInjectable from "../../../../common/helm/get-active-helm-repositories-channel.injectable";
|
||||
import { getActiveHelmRepositoriesChannel } from "../../../../common/helm/get-active-helm-repositories-channel";
|
||||
import { getRequestChannelListenerInjectable } from "../../../utils/channel/channel-listeners/listener-tokens";
|
||||
import getActiveHelmRepositoriesInjectable from "./get-active-helm-repositories.injectable";
|
||||
|
||||
const getActiveHelmRepositoriesChannelListenerInjectable = getInjectable({
|
||||
id: "get-active-helm-repositories-channel-listener",
|
||||
|
||||
instantiate: (di) => {
|
||||
const getActiveHelmRepositories = di.inject(getActiveHelmRepositoriesInjectable);
|
||||
|
||||
return {
|
||||
channel: di.inject(getActiveHelmRepositoriesChannelInjectable),
|
||||
|
||||
handler: getActiveHelmRepositories,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: requestChannelListenerInjectionToken,
|
||||
const getActiveHelmRepositoriesChannelListenerInjectable = getRequestChannelListenerInjectable({
|
||||
channel: getActiveHelmRepositoriesChannel,
|
||||
handler: (di) => di.inject(getActiveHelmRepositoriesInjectable),
|
||||
});
|
||||
|
||||
export default getActiveHelmRepositoriesChannelListenerInjectable;
|
||||
+5
-17
@@ -2,25 +2,13 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { requestChannelListenerInjectionToken } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||
import removeHelmRepositoryInjectable from "./remove-helm-repository.injectable";
|
||||
import removeHelmRepositoryChannelInjectable from "../../../../common/helm/remove-helm-repository-channel.injectable";
|
||||
import { removeHelmRepositoryChannel } from "../../../../common/helm/remove-helm-repository-channel";
|
||||
import { getRequestChannelListenerInjectable } from "../../../utils/channel/channel-listeners/listener-tokens";
|
||||
|
||||
const removeHelmRepositoryChannelListenerInjectable = getInjectable({
|
||||
id: "remove-helm-repository-channel-listener",
|
||||
|
||||
instantiate: (di) => {
|
||||
const removeHelmRepository = di.inject(removeHelmRepositoryInjectable);
|
||||
const channel = di.inject(removeHelmRepositoryChannelInjectable);
|
||||
|
||||
return {
|
||||
channel,
|
||||
handler: removeHelmRepository,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: requestChannelListenerInjectionToken,
|
||||
const removeHelmRepositoryChannelListenerInjectable = getRequestChannelListenerInjectable({
|
||||
channel: removeHelmRepositoryChannel,
|
||||
handler: (di) => di.inject(removeHelmRepositoryInjectable),
|
||||
});
|
||||
|
||||
export default removeHelmRepositoryChannelListenerInjectable;
|
||||
Reference in new issue
Block a user