mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add new Result type to complement AsyncResult
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
63ad078d63
commit
cb9d978e5a
@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import execFileInjectable from "../fs/exec-file.injectable";
|
||||
import loggerInjectable from "../logger.injectable";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import type { AsyncResult } from "../utils/result";
|
||||
import { requestSystemCAsInjectionToken } from "./request-system-cas-token";
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet#other_assertions
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { RequestInit, Response } from "node-fetch";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import type { AsyncResult } from "../utils/result";
|
||||
import fetchInjectable from "./fetch.injectable";
|
||||
|
||||
export interface DownloadBinaryOptions {
|
||||
|
||||
@ -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 { AsyncResult } from "../../utils/async-result";
|
||||
import type { AsyncResult } from "../../utils/result";
|
||||
import type { Fetch } from "../fetch.injectable";
|
||||
import type { RequestInit, Response } from "node-fetch";
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { ExecFileException, ExecFileOptions } from "child_process";
|
||||
import { execFile } from "child_process";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import type { AsyncResult } from "../utils/result";
|
||||
|
||||
export type ExecFileError = ExecFileException & { stderr: string };
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import type { AsyncResult } from "../utils/result";
|
||||
import { isErrnoException } from "../utils";
|
||||
import type { Stats } from "fs-extra";
|
||||
import { lowerFirst } from "lodash/fp";
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { HelmRepo } from "./helm-repo";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import type { AsyncResult } from "../utils/result";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
|
||||
|
||||
export type AddHelmRepositoryChannel = RequestChannel<HelmRepo, AsyncResult<void, string>>;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { HelmRepo } from "./helm-repo";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import type { AsyncResult } from "../utils/result";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
|
||||
|
||||
export type GetActiveHelmRepositoriesChannel = RequestChannel<void, AsyncResult<HelmRepo[]>>;
|
||||
|
||||
@ -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 { AsyncResult } from "../utils/async-result";
|
||||
import type { AsyncResult } from "../utils/result";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
|
||||
import type { HelmRepo } from "./helm-repo";
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "../../../utils/async-result";
|
||||
import type { AsyncResult } from "../../../utils/result";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "../../../utils/async-result";
|
||||
import type { AsyncResult } from "../../../utils/result";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import type { AsyncResult } from "../../../utils/async-result";
|
||||
import type { AsyncResult } from "../../../utils/result";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
interface HelmReleaseUpdatePayload {
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { Patch } from "rfc6902";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
import type { AsyncResult } from "../../../utils/async-result";
|
||||
import type { AsyncResult } from "../../../utils/result";
|
||||
import type { KubeJsonApiData } from "../../kube-json-api";
|
||||
|
||||
export type RequestKubeObjectPatch = (name: string, kind: string, ns: string | undefined, patch: Patch) => Promise<AsyncResult<KubeJsonApiData, string>>;
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
import type { AsyncResult } from "../../../utils/async-result";
|
||||
import type { AsyncResult } from "../../../utils/result";
|
||||
import type { KubeJsonApiData } from "../../kube-json-api";
|
||||
|
||||
export type RequestKubeObjectCreation = (resourceDescriptor: string) => Promise<AsyncResult<KubeJsonApiData, string>>;
|
||||
|
||||
@ -7,7 +7,7 @@ import type { KubernetesCluster } from "../catalog-entities";
|
||||
import yaml from "js-yaml";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import productNameInjectable from "../vars/product-name.injectable";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import type { AsyncResult } from "../utils/result";
|
||||
import type { Logger } from "../logger";
|
||||
import type { KubectlApplyAll, KubectlDeleteAll } from "../kube-helpers/channels";
|
||||
import type { ReadDirectory } from "../fs/read-directory.injectable";
|
||||
|
||||
@ -7,7 +7,7 @@ import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { Asyncify } from "type-fest";
|
||||
import type { RequestChannelHandler } from "../../main/utils/channel/channel-listeners/listener-tokens";
|
||||
import type { ClusterId } from "../cluster-types";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import type { AsyncResult } from "../utils/result";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
|
||||
|
||||
export interface KubectlApplyAllArgs {
|
||||
|
||||
@ -2,6 +2,15 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
export type Result<Value, Error = string> =
|
||||
| (
|
||||
Value extends void
|
||||
? { isOk: true; value?: undefined; error?: never }
|
||||
: { isOk: true; value: Value; error?: never }
|
||||
)
|
||||
| { isOk: false; value?: never; error: Error };
|
||||
|
||||
export type AsyncResult<Response, Error = string> =
|
||||
| (
|
||||
Response extends void
|
||||
@ -17,7 +17,7 @@ import requestPublicHelmRepositoriesInjectable from "./child-features/preference
|
||||
import isPathInjectable from "../../renderer/components/input/validators/is-path.injectable";
|
||||
import showSuccessNotificationInjectable from "../../renderer/components/notifications/show-success-notification.injectable";
|
||||
import showErrorNotificationInjectable from "../../renderer/components/notifications/show-error-notification.injectable";
|
||||
import type { AsyncResult } from "../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../common/utils/result";
|
||||
|
||||
describe("add custom helm repository in preferences", () => {
|
||||
let builder: ApplicationBuilder;
|
||||
|
||||
@ -15,7 +15,7 @@ import type { HelmRepo } from "../../common/helm/helm-repo";
|
||||
import requestPublicHelmRepositoriesInjectable from "./child-features/preferences/renderer/adding-of-public-helm-repository/public-helm-repositories/request-public-helm-repositories.injectable";
|
||||
import showSuccessNotificationInjectable from "../../renderer/components/notifications/show-success-notification.injectable";
|
||||
import showErrorNotificationInjectable from "../../renderer/components/notifications/show-error-notification.injectable";
|
||||
import type { AsyncResult } from "../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../common/utils/result";
|
||||
|
||||
describe("add helm repository from list in preferences", () => {
|
||||
let builder: ApplicationBuilder;
|
||||
|
||||
@ -14,7 +14,7 @@ import helmBinaryPathInjectable from "../../main/helm/helm-binary-path.injectabl
|
||||
import getActiveHelmRepositoriesInjectable from "../../main/helm/repositories/get-active-helm-repositories/get-active-helm-repositories.injectable";
|
||||
import type { HelmRepo } from "../../common/helm/helm-repo";
|
||||
import requestPublicHelmRepositoriesInjectable from "./child-features/preferences/renderer/adding-of-public-helm-repository/public-helm-repositories/request-public-helm-repositories.injectable";
|
||||
import type { AsyncResult } from "../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../common/utils/result";
|
||||
|
||||
describe("remove helm repository from list of active repositories in preferences", () => {
|
||||
let builder: ApplicationBuilder;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { AsyncResult } from "../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../../common/utils/result";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import isWindowsInjectable from "../../../common/vars/is-windows.injectable";
|
||||
import computeUnixShellEnvironmentInjectable from "./compute-unix-shell-environment.injectable";
|
||||
|
||||
@ -11,7 +11,7 @@ import loggerInjectable from "../../../common/logger.injectable";
|
||||
import processExecPathInjectable from "./execPath.injectable";
|
||||
import processEnvInjectable from "./env.injectable";
|
||||
import { object } from "../../../common/utils";
|
||||
import type { AsyncResult } from "../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../../common/utils/result";
|
||||
|
||||
export interface UnixShellEnvOptions {
|
||||
signal: AbortSignal;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
||||
import listHelmChartsInjectable from "../helm-service/list-helm-charts.injectable";
|
||||
import getActiveHelmRepositoriesInjectable from "../repositories/get-active-helm-repositories/get-active-helm-repositories.injectable";
|
||||
import type { AsyncResult } from "../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../../common/utils/result";
|
||||
import type { HelmRepo } from "../../../common/helm/helm-repo";
|
||||
import { sortBySemverVersion } from "../../../common/utils";
|
||||
import helmChartManagerInjectable from "../helm-chart-manager.injectable";
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { ExecFileException } from "child_process";
|
||||
import execFileInjectable from "../../../common/fs/exec-file.injectable";
|
||||
import type { AsyncResult } from "../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../../common/utils/result";
|
||||
import helmBinaryPathInjectable from "../helm-binary-path.injectable";
|
||||
import execHelmEnvInjectable from "./exec-env.injectable";
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import execHelmInjectable from "../exec-helm/exec-helm.injectable";
|
||||
import type { AsyncResult } from "../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../../common/utils/result";
|
||||
|
||||
export type HelmEnv = Record<string, string> & {
|
||||
HELM_REPOSITORY_CACHE?: string;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "../../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../../../../common/utils/result";
|
||||
import execHelmInjectable from "../../../exec-helm/exec-helm.injectable";
|
||||
import yaml from "js-yaml";
|
||||
import type { KubeJsonApiData, KubeJsonApiDataList } from "../../../../../common/k8s-api/kube-json-api";
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "../../../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../../../../../common/utils/result";
|
||||
import nonPromiseExecFileInjectable from "./non-promise-exec-file.injectable";
|
||||
import { isNumber } from "../../../../../../common/utils";
|
||||
import assert from "assert";
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
import { getDiForUnitTesting } from "../../../../../getDiForUnitTesting";
|
||||
import type { ExecFileWithInput } from "./exec-file-with-input.injectable";
|
||||
import execFileWithInputInjectable from "./exec-file-with-input.injectable";
|
||||
import type { AsyncResult } from "../../../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../../../../../common/utils/result";
|
||||
import nonPromiseExecFileInjectable from "./non-promise-exec-file.injectable";
|
||||
import { getPromiseStatus } from "../../../../../../common/test-utils/get-promise-status";
|
||||
import EventEmitter from "events";
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import callForHelmManifestInjectable from "./call-for-helm-manifest/call-for-helm-manifest.injectable";
|
||||
import type { KubeJsonApiData, KubeJsonApiDataList } from "../../../../common/k8s-api/kube-json-api";
|
||||
import type { AsyncResult } from "../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../../../common/utils/result";
|
||||
|
||||
export type GetHelmReleaseResources = (
|
||||
name: string,
|
||||
|
||||
@ -12,7 +12,7 @@ import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import type { ExecFileWithInput } from "./call-for-kube-resources-by-manifest/exec-file-with-input/exec-file-with-input.injectable";
|
||||
import execFileWithInputInjectable from "./call-for-kube-resources-by-manifest/exec-file-with-input/exec-file-with-input.injectable";
|
||||
import type { AsyncResult } from "../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../../../common/utils/result";
|
||||
import type { KubeJsonApiData } from "../../../../common/k8s-api/kube-json-api";
|
||||
|
||||
describe("get helm release resources", () => {
|
||||
|
||||
@ -9,7 +9,7 @@ import readYamlFileInjectable from "../../../../common/fs/read-yaml-file.injecta
|
||||
import getHelmEnvInjectable from "../../get-helm-env/get-helm-env.injectable";
|
||||
import execHelmInjectable from "../../exec-helm/exec-helm.injectable";
|
||||
import loggerInjectable from "../../../../common/logger.injectable";
|
||||
import type { AsyncResult } from "../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../../../common/utils/result";
|
||||
|
||||
interface HelmRepositoryFromYaml {
|
||||
name: string;
|
||||
|
||||
@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import execHelmInjectable from "../../exec-helm/exec-helm.injectable";
|
||||
import type { HelmRepo } from "../../../../common/helm/helm-repo";
|
||||
import loggerInjectable from "../../../../common/logger.injectable";
|
||||
import type { AsyncResult } from "../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../../../common/utils/result";
|
||||
|
||||
const removeHelmRepositoryInjectable = getInjectable({
|
||||
id: "remove-helm-repository",
|
||||
|
||||
@ -14,7 +14,7 @@ import type { WriteFile } from "../../common/fs/write-file.injectable";
|
||||
import type { RemovePath } from "../../common/fs/remove.injectable";
|
||||
import type { ExecFile } from "../../common/fs/exec-file.injectable";
|
||||
import type { JoinPaths } from "../../common/path/join-paths.injectable";
|
||||
import type { AsyncResult } from "../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../common/utils/result";
|
||||
|
||||
export interface ResourceApplierDependencies {
|
||||
emitAppEvent: EmitAppEvent;
|
||||
|
||||
@ -7,7 +7,7 @@ import type { HelmReleaseDto } from "../../../../../common/k8s-api/endpoints/hel
|
||||
import requestHelmReleasesInjectable from "../../../../../common/k8s-api/endpoints/helm-releases.api/request-releases.injectable";
|
||||
import type { HelmReleaseDetails } from "../../../../../common/k8s-api/endpoints/helm-releases.api/request-details.injectable";
|
||||
import requestHelmReleaseDetailsInjectable from "../../../../../common/k8s-api/endpoints/helm-releases.api/request-details.injectable";
|
||||
import type { AsyncResult } from "../../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../../../../common/utils/result";
|
||||
|
||||
export interface DetailedHelmRelease {
|
||||
release: HelmReleaseDto;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "../../../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../../../../../common/utils/result";
|
||||
import apiManagerInjectable from "../../../../../../common/k8s-api/api-manager/manager.injectable";
|
||||
import type { JsonPatch } from "../../../../../../common/k8s-api/kube-object.store";
|
||||
import type { KubeObject } from "../../../../../../common/k8s-api/kube-object";
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { KubeObject } from "../../../../../../common/k8s-api/kube-object";
|
||||
import { parseKubeApi } from "../../../../../../common/k8s-api/kube-api-parse";
|
||||
import type { AsyncResult } from "../../../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../../../../../common/utils/result";
|
||||
import { getErrorMessage } from "../../../../../../common/utils/get-error-message";
|
||||
import apiManagerInjectable from "../../../../../../common/k8s-api/api-manager/manager.injectable";
|
||||
import { waitUntilDefined } from "../../../../../../common/utils";
|
||||
|
||||
@ -13,7 +13,7 @@ import releasesInjectable from "../../+helm-releases/releases.injectable";
|
||||
import updateReleaseInjectable from "../../+helm-releases/update-release/update-release.injectable";
|
||||
import type { HelmRelease } from "../../../../common/k8s-api/endpoints/helm-releases.api";
|
||||
import requestHelmReleaseConfigurationInjectable from "../../../../common/k8s-api/endpoints/helm-releases.api/request-configuration.injectable";
|
||||
import type { AsyncResult } from "../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "../../../../common/utils/result";
|
||||
import { waitUntilDefined } from "../../../utils";
|
||||
import type { SelectOption } from "../../select";
|
||||
import type { DockTab } from "../dock/store";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user