1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Replace all internal uses of utilities with new packages

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-03-02 10:33:48 -05:00
parent 3a2e436933
commit ef32f2b72b
410 changed files with 1222 additions and 825 deletions

378
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -330,6 +330,8 @@
}, },
"peerDependencies": { "peerDependencies": {
"@k8slens/application": "^6.5.0-alpha.0", "@k8slens/application": "^6.5.0-alpha.0",
"@k8slens/test-utils": "^1.0.0",
"@k8slens/utilities": "^1.0.0",
"@types/byline": "^4.2.33", "@types/byline": "^4.2.33",
"@types/chart.js": "^2.9.36", "@types/chart.js": "^2.9.36",
"@types/color": "^3.0.3", "@types/color": "^3.0.3",

View File

@ -7,7 +7,7 @@ import type Config from "conf";
import type { Migrations, Options as ConfOptions } from "conf/dist/source/types"; import type { Migrations, Options as ConfOptions } from "conf/dist/source/types";
import type { IEqualsComparer } from "mobx"; import type { IEqualsComparer } from "mobx";
import { makeObservable, reaction } from "mobx"; import { makeObservable, reaction } from "mobx";
import { disposer, isPromiseLike, toJS } from "../utils"; import { disposer, isPromiseLike } from "@k8slens/utilities";
import { broadcastMessage } from "../ipc"; import { broadcastMessage } from "../ipc";
import isEqual from "lodash/isEqual"; import isEqual from "lodash/isEqual";
import { kebabCase } from "lodash"; import { kebabCase } from "lodash";
@ -16,6 +16,7 @@ import type { Logger } from "../logger";
import type { PersistStateToConfig } from "./save-to-file"; import type { PersistStateToConfig } from "./save-to-file";
import type { GetBasenameOfPath } from "../path/get-basename.injectable"; import type { GetBasenameOfPath } from "../path/get-basename.injectable";
import type { EnlistMessageChannelListener } from "../utils/channel/enlist-message-channel-listener-injection-token"; import type { EnlistMessageChannelListener } from "../utils/channel/enlist-message-channel-listener-injection-token";
import { toJS } from "../utils";
export interface BaseStoreParams<T> extends Omit<ConfOptions<T>, "migrations"> { export interface BaseStoreParams<T> extends Omit<ConfOptions<T>, "migrations"> {
syncOptions?: { syncOptions?: {

View File

@ -7,7 +7,7 @@ import { lifecycleEnum, getInjectable } from "@ogre-tools/injectable";
import type Conf from "conf/dist/source"; import type Conf from "conf/dist/source";
import type { Migrations } from "conf/dist/source/types"; import type { Migrations } from "conf/dist/source/types";
import loggerInjectable from "../logger.injectable"; import loggerInjectable from "../logger.injectable";
import { getOrInsert, iter } from "../utils"; import { getOrInsert, iter } from "@k8slens/utilities";
export interface MigrationDeclaration { export interface MigrationDeclaration {
version: string; version: string;

View File

@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { generalCatalogEntityInjectionToken } from "../general-catalog-entity-injection-token"; import { generalCatalogEntityInjectionToken } from "../general-catalog-entity-injection-token";
import { GeneralEntity } from "../../index"; import { GeneralEntity } from "../../index";
import { buildURL } from "../../../utils/buildUrl"; import { buildURL } from "@k8slens/utilities";
import catalogRouteInjectable from "../../../front-end-routing/routes/catalog/catalog-route.injectable"; import catalogRouteInjectable from "../../../front-end-routing/routes/catalog/catalog-route.injectable";
const catalogCatalogEntityInjectable = getInjectable({ const catalogCatalogEntityInjectable = getInjectable({

View File

@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { generalCatalogEntityInjectionToken } from "../general-catalog-entity-injection-token"; import { generalCatalogEntityInjectionToken } from "../general-catalog-entity-injection-token";
import { GeneralEntity } from "../../index"; import { GeneralEntity } from "../../index";
import { buildURL } from "../../../utils/buildUrl"; import { buildURL } from "@k8slens/utilities/src/buildUrl";
import welcomeRouteInjectable from "../../../front-end-routing/routes/welcome/welcome-route.injectable"; import welcomeRouteInjectable from "../../../front-end-routing/routes/welcome/welcome-route.injectable";
const welcomeCatalogEntityInjectable = getInjectable({ const welcomeCatalogEntityInjectable = getInjectable({

View File

@ -7,8 +7,8 @@ import EventEmitter from "events";
import type TypedEmitter from "typed-emitter"; import type TypedEmitter from "typed-emitter";
import { observable, makeObservable } from "mobx"; import { observable, makeObservable } from "mobx";
import { once } from "lodash"; import { once } from "lodash";
import type { Disposer } from "../utils"; import type { Disposer } from "@k8slens/utilities";
import { iter } from "../utils"; import { iter } from "@k8slens/utilities";
import type { CategoryColumnRegistration, TitleCellProps } from "../../renderer/components/+catalog/custom-category-columns"; import type { CategoryColumnRegistration, TitleCellProps } from "../../renderer/components/+catalog/custom-category-columns";
export type { CategoryColumnRegistration, TitleCellProps }; export type { CategoryColumnRegistration, TitleCellProps };

View File

@ -5,8 +5,8 @@
import { action, computed, observable, makeObservable } from "mobx"; import { action, computed, observable, makeObservable } from "mobx";
import { once } from "lodash"; import { once } from "lodash";
import { iter, getOrInsertMap, strictSet } from "../utils"; import { iter, getOrInsertMap, strictSet } from "@k8slens/utilities";
import type { Disposer } from "../utils"; import type { Disposer } from "@k8slens/utilities";
import type { CatalogCategory, CatalogEntityData, CatalogEntityKindData } from "./catalog-entity"; import type { CatalogCategory, CatalogEntityData, CatalogEntityKindData } from "./catalog-entity";
export type CategoryFilter = (category: CatalogCategory) => any; export type CategoryFilter = (category: CatalogCategory) => any;

View File

@ -11,10 +11,10 @@ import type { Kubectl } from "../../main/kubectl/kubectl";
import type { KubeconfigManager } from "../../main/kubeconfig-manager/kubeconfig-manager"; import type { KubeconfigManager } from "../../main/kubeconfig-manager/kubeconfig-manager";
import type { KubeApiResource, KubeApiResourceDescriptor } from "../rbac"; import type { KubeApiResource, KubeApiResourceDescriptor } from "../rbac";
import { formatKubeApiResource } from "../rbac"; import { formatKubeApiResource } from "../rbac";
import plimit from "p-limit";
import type { ClusterState, ClusterMetricsResourceType, ClusterId, ClusterMetadata, ClusterModel, ClusterPreferences, ClusterPrometheusPreferences, UpdateClusterModel, KubeAuthUpdate, ClusterConfigData } from "../cluster-types"; import type { ClusterState, ClusterMetricsResourceType, ClusterId, ClusterMetadata, ClusterModel, ClusterPreferences, ClusterPrometheusPreferences, UpdateClusterModel, KubeAuthUpdate, ClusterConfigData } from "../cluster-types";
import { ClusterMetadataKey, initialNodeShellImage, ClusterStatus, clusterModelIdChecker, updateClusterModelChecker } from "../cluster-types"; import { ClusterMetadataKey, initialNodeShellImage, ClusterStatus, clusterModelIdChecker, updateClusterModelChecker } from "../cluster-types";
import { disposer, isDefined, isRequestError, toJS } from "../utils"; import { disposer, isDefined, isRequestError, withConcurrencyLimit } from "@k8slens/utilities";
import { toJS } from "../utils";
import { clusterListNamespaceForbiddenChannel } from "../ipc/cluster"; import { clusterListNamespaceForbiddenChannel } from "../ipc/cluster";
import type { CanI } from "./authorization-review.injectable"; import type { CanI } from "./authorization-review.injectable";
import type { ListNamespaces } from "./list-namespaces.injectable"; import type { ListNamespaces } from "./list-namespaces.injectable";
@ -683,10 +683,11 @@ export class Cluster implements ClusterModel {
return []; return [];
} }
const apiLimit = withConcurrencyLimit(5);
try { try {
const apiLimit = plimit(5); // 5 concurrent api requests
const canListResourceCheckers = await Promise.all(( const canListResourceCheckers = await Promise.all((
this.allowedNamespaces.map(namespace => apiLimit(() => requestNamespaceListPermissions(namespace))) this.allowedNamespaces.map(namespace => apiLimit(() => requestNamespaceListPermissions(namespace))())
)); ));
const canListNamespacedResource: CanListResource = (resource) => canListResourceCheckers.some(fn => fn(resource)); const canListNamespacedResource: CanListResource = (resource) => canListResourceCheckers.some(fn => fn(resource));

View File

@ -5,7 +5,7 @@
import type { KubeConfig } from "@kubernetes/client-node"; import type { KubeConfig } from "@kubernetes/client-node";
import { CoreV1Api } from "@kubernetes/client-node"; import { CoreV1Api } from "@kubernetes/client-node";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { isDefined } from "../utils"; import { isDefined } from "@k8slens/utilities";
export type ListNamespaces = () => Promise<string[]>; export type ListNamespaces = () => Promise<string[]>;

View File

@ -4,14 +4,14 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { RequestInit, Response } from "@k8slens/node-fetch"; import type { RequestInit, Response } from "@k8slens/node-fetch";
import type { AsyncResult } from "../utils/async-result"; import type { AsyncResult } from "@k8slens/utilities";
import fetchInjectable from "./fetch.injectable"; import fetchInjectable from "./fetch.injectable";
export interface DownloadBinaryOptions { export interface DownloadBinaryOptions {
signal?: AbortSignal | null | undefined; signal?: AbortSignal | null | undefined;
} }
export type DownloadBinary = (url: string, opts?: DownloadBinaryOptions) => Promise<AsyncResult<Buffer, string>>; export type DownloadBinary = (url: string, opts?: DownloadBinaryOptions) => AsyncResult<Buffer, string>;
const downloadBinaryInjectable = getInjectable({ const downloadBinaryInjectable = getInjectable({
id: "download-binary", id: "download-binary",

View File

@ -2,7 +2,7 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { AsyncResult } from "../../utils/async-result"; import type { AsyncResult } from "@k8slens/utilities";
import type { Fetch } from "../fetch.injectable"; import type { Fetch } from "../fetch.injectable";
import type { RequestInit, Response } from "@k8slens/node-fetch"; import type { RequestInit, Response } from "@k8slens/node-fetch";
@ -10,7 +10,7 @@ export interface DownloadJsonOptions {
signal?: AbortSignal | null | undefined; signal?: AbortSignal | null | undefined;
} }
export type DownloadJson = (url: string, opts?: DownloadJsonOptions) => Promise<AsyncResult<unknown, string>>; export type DownloadJson = (url: string, opts?: DownloadJsonOptions) => AsyncResult<unknown, string>;
export const downloadJsonWith = (fetch: Fetch): DownloadJson => async (url, opts) => { export const downloadJsonWith = (fetch: Fetch): DownloadJson => async (url, opts) => {
let result: Response; let result: Response;

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getGlobalOverrideForFunction } from "../test-utils/get-global-override-for-function"; import { getGlobalOverrideForFunction } from "../../../../utility-features/test-utils/src/get-global-override-for-function";
import fetchInjectable from "./fetch.injectable"; import fetchInjectable from "./fetch.injectable";
export default getGlobalOverrideForFunction(fetchInjectable); export default getGlobalOverrideForFunction(fetchInjectable);

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getGlobalOverrideForFunction } from "../test-utils/get-global-override-for-function"; import { getGlobalOverrideForFunction } from "../../../../utility-features/test-utils/src/get-global-override-for-function";
import lensFetchInjectable from "./lens-fetch.injectable"; import lensFetchInjectable from "./lens-fetch.injectable";
export default getGlobalOverrideForFunction(lensFetchInjectable); export default getGlobalOverrideForFunction(lensFetchInjectable);

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; import { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token";
import { computedOr } from "../../../../../utils/computed-or"; import { computedOr } from "@k8slens/utilities";
import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token";
const ingressesRouteInjectable = getInjectable({ const ingressesRouteInjectable = getInjectable({

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getGlobalOverrideForFunction } from "../test-utils/get-global-override-for-function"; import { getGlobalOverrideForFunction } from "../../../../utility-features/test-utils/src/get-global-override-for-function";
import execFileInjectable from "./exec-file.injectable"; import execFileInjectable from "./exec-file.injectable";
export default getGlobalOverrideForFunction(execFileInjectable); export default getGlobalOverrideForFunction(execFileInjectable);

View File

@ -5,14 +5,14 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { ExecFileException, ExecFileOptions } from "child_process"; import type { ExecFileException, ExecFileOptions } from "child_process";
import { execFile } from "child_process"; import { execFile } from "child_process";
import type { AsyncResult } from "../utils/async-result"; import type { AsyncResult } from "@k8slens/utilities";
export type ExecFileError = ExecFileException & { stderr: string }; export type ExecFileError = ExecFileException & { stderr: string };
export interface ExecFile { export interface ExecFile {
(filePath: string): Promise<AsyncResult<string, ExecFileError>>; (filePath: string): AsyncResult<string, ExecFileError>;
(filePath: string, argsOrOptions: string[] | ExecFileOptions): Promise<AsyncResult<string, ExecFileError>>; (filePath: string, argsOrOptions: string[] | ExecFileOptions): AsyncResult<string, ExecFileError>;
(filePath: string, args: string[], options: ExecFileOptions): Promise<AsyncResult<string, ExecFileError>>; (filePath: string, args: string[], options: ExecFileOptions): AsyncResult<string, ExecFileError>;
} }
const execFileInjectable = getInjectable({ const execFileInjectable = getInjectable({

View File

@ -21,6 +21,7 @@ const fsInjectable = getInjectable({
rm, rm,
access, access,
stat, stat,
unlink,
}, },
ensureDir, ensureDir,
ensureDirSync, ensureDirSync,
@ -56,6 +57,7 @@ const fsInjectable = getInjectable({
ensureDirSync, ensureDirSync,
createReadStream, createReadStream,
stat, stat,
unlink,
}; };
}, },
causesSideEffects: true, causesSideEffects: true,

View File

@ -0,0 +1,15 @@
/**
* 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 fsInjectable from "./fs.injectable";
export type Unlink = (path: string) => Promise<void>;
const unlinkInjectable = getInjectable({
id: "unlink",
instantiate: (di): Unlink => di.inject(fsInjectable).unlink,
});
export default unlinkInjectable;

View File

@ -3,13 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { AsyncResult } from "../utils/async-result"; import type { AsyncResult } from "@k8slens/utilities";
import { isErrnoException } from "../utils"; import { isErrnoException } from "@k8slens/utilities";
import type { Stats } from "fs-extra"; import type { Stats } from "fs-extra";
import { lowerFirst } from "lodash/fp"; import { lowerFirst } from "lodash/fp";
import statInjectable from "./stat.injectable"; import statInjectable from "./stat.injectable";
export type ValidateDirectory = (path: string) => Promise<AsyncResult<undefined>>; export type ValidateDirectory = (path: string) => AsyncResult<undefined>;
function getUserReadableFileType(stats: Stats): string { function getUserReadableFileType(stats: Stats): string {
if (stats.isFile()) { if (stats.isFile()) {

View File

@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
import { watch } from "chokidar"; import { watch } from "chokidar";
import type { Stats } from "fs"; import type { Stats } from "fs";
import type TypedEventEmitter from "typed-emitter"; import type TypedEventEmitter from "typed-emitter";
import type { SingleOrMany } from "../../utils"; import type { SingleOrMany } from "@k8slens/utilities";
export interface AlwaysStatWatcherEvents { export interface AlwaysStatWatcherEvents {
add: (path: string, stats: Stats) => void; add: (path: string, stats: Stats) => void;

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { HelmRepo } from "./helm-repo"; import type { HelmRepo } from "./helm-repo";
import type { AsyncResult } from "../utils/async-result"; import type { AsyncResult } from "@k8slens/utilities";
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token"; import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
export type AddHelmRepositoryChannel = RequestChannel<HelmRepo, AsyncResult<void, string>>; export type AddHelmRepositoryChannel = RequestChannel<HelmRepo, AsyncResult<void, string>>;

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { HelmRepo } from "./helm-repo"; import type { HelmRepo } from "./helm-repo";
import type { AsyncResult } from "../utils/async-result"; import type { AsyncResult } from "@k8slens/utilities";
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token"; import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
export type GetActiveHelmRepositoriesChannel = RequestChannel<void, AsyncResult<HelmRepo[]>>; export type GetActiveHelmRepositoriesChannel = RequestChannel<void, AsyncResult<HelmRepo[]>>;

View File

@ -2,7 +2,7 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { AsyncResult } from "../utils/async-result"; import type { AsyncResult } from "@k8slens/utilities";
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token"; import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
import type { HelmRepo } from "./helm-repo"; import type { HelmRepo } from "./helm-repo";

View File

@ -4,8 +4,8 @@
*/ */
import * as uuid from "uuid"; import * as uuid from "uuid";
import type { Tuple } from "../utils"; import type { Tuple } from "@k8slens/utilities";
import { tuple } from "../utils"; import { tuple } from "@k8slens/utilities";
export interface HotbarItem { export interface HotbarItem {
entity: { entity: {

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getGlobalOverrideForFunction } from "../test-utils/get-global-override-for-function"; import { getGlobalOverrideForFunction } from "../../../../utility-features/test-utils/src/get-global-override-for-function";
import broadcastMessageInjectable from "./broadcast-message.injectable"; import broadcastMessageInjectable from "./broadcast-message.injectable";
export default getGlobalOverrideForFunction(broadcastMessageInjectable); export default getGlobalOverrideForFunction(broadcastMessageInjectable);

View File

@ -11,7 +11,7 @@ import { ipcMain, ipcRenderer, webContents } from "electron";
import { toJS } from "../utils/toJS"; import { toJS } from "../utils/toJS";
import type { ClusterFrameInfo } from "../cluster-frames"; import type { ClusterFrameInfo } from "../cluster-frames";
import { clusterFrameMap } from "../cluster-frames"; import { clusterFrameMap } from "../cluster-frames";
import type { Disposer } from "../utils"; import type { Disposer } from "@k8slens/utilities";
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import ipcRendererInjectable from "../../renderer/utils/channel/ipc-renderer.injectable"; import ipcRendererInjectable from "../../renderer/utils/channel/ipc-renderer.injectable";
import loggerInjectable from "../logger.injectable"; import loggerInjectable from "../logger.injectable";

View File

@ -3,8 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import autoBind from "auto-bind";
import orderBy from "lodash/orderBy"; import orderBy from "lodash/orderBy";
import { autoBind } from "./utils";
import { action, computed, observable, when, makeObservable } from "mobx"; import { action, computed, observable, when, makeObservable } from "mobx";
export interface ItemObject { export interface ItemObject {

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { noop } from "../../utils"; import { noop } from "@k8slens/utilities";
import type { KubeApi } from "../kube-api"; import type { KubeApi } from "../kube-api";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { KubeObjectStoreLoadingParams } from "../kube-object.store"; import type { KubeObjectStoreLoadingParams } from "../kube-object.store";

View File

@ -10,7 +10,7 @@ import { autorun, action, observable } from "mobx";
import type { KubeApi } from "../kube-api"; import type { KubeApi } from "../kube-api";
import type { KubeObject, ObjectReference } from "../kube-object"; import type { KubeObject, ObjectReference } from "../kube-object";
import { parseKubeApi, createKubeApiURL } from "../kube-api-parse"; import { parseKubeApi, createKubeApiURL } from "../kube-api-parse";
import { chain, find } from "../../utils/iter"; import { chain, find } from "@k8slens/utilities/src/iter";
export type RegisterableStore<Store> = Store extends KubeObjectStore<any, any, any> export type RegisterableStore<Store> = Store extends KubeObjectStore<any, any, any>
? Store ? Store

View File

@ -8,7 +8,7 @@ import { KubeObject } from "../kube-object";
import type { KubeJsonApiData } from "../kube-json-api"; import type { KubeJsonApiData } from "../kube-json-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api"; import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import { autoBind } from "../../utils"; import autoBind from "auto-bind";
export interface ConfigMapData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectScope.Namespace>, void, void> { export interface ConfigMapData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectScope.Namespace>, void, void> {
data?: Partial<Record<string, string>>; data?: Partial<Record<string, string>>;

View File

@ -6,7 +6,7 @@
import moment from "moment"; import moment from "moment";
import type { NamespaceScopedMetadata, ObjectReference } from "../kube-object"; import type { NamespaceScopedMetadata, ObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import { formatDuration } from "../../utils/formatDuration"; import { formatDuration } from "@k8slens/utilities";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api"; import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import type { JobTemplateSpec } from "./types/job-template-spec"; import type { JobTemplateSpec } from "./types/job-template-spec";

View File

@ -5,7 +5,7 @@
import { getLegacyGlobalDiForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import { getLegacyGlobalDiForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import customResourcesRouteInjectable from "../../front-end-routing/routes/cluster/custom-resources/custom-resources/custom-resources-route.injectable"; import customResourcesRouteInjectable from "../../front-end-routing/routes/cluster/custom-resources/custom-resources/custom-resources-route.injectable";
import { buildURL } from "../../utils/buildUrl"; import { buildURL } from "@k8slens/utilities/src/buildUrl";
import type { BaseKubeObjectCondition, ClusterScopedMetadata } from "../kube-object"; import type { BaseKubeObjectCondition, ClusterScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api"; import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";

View File

@ -10,7 +10,7 @@ import { KubeApi } from "../kube-api";
import type { PodSpec } from "./pod.api"; import type { PodSpec } from "./pod.api";
import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object"; import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import { hasTypedProperty, isNumber, isObject } from "../../utils"; import { hasTypedProperty, isNumber, isObject } from "@k8slens/utilities";
export class DeploymentApi extends KubeApi<Deployment> { export class DeploymentApi extends KubeApi<Deployment> {
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { autoBind } from "../../utils"; import autoBind from "auto-bind";
import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata, ObjectReference } from "../kube-object"; import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata, ObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api"; import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";

View File

@ -6,7 +6,7 @@
import moment from "moment"; import moment from "moment";
import type { KubeObjectMetadata, KubeObjectScope, ObjectReference } from "../kube-object"; import type { KubeObjectMetadata, KubeObjectScope, ObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import { formatDuration } from "../../utils/formatDuration"; import { formatDuration } from "@k8slens/utilities";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api"; import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api"; import type { KubeJsonApiData } from "../kube-json-api";

View File

@ -3,7 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { autoBind, bifurcateArray } from "../../utils"; import { array } from "@k8slens/utilities";
import autoBind from "auto-bind";
import Joi from "joi"; import Joi from "joi";
export interface RawHelmChart { export interface RawHelmChart {
@ -263,7 +264,7 @@ export class HelmChart implements HelmChartData {
return new HelmChart(result.value); return new HelmChart(result.value);
} }
const [actualErrors, unknownDetails] = bifurcateArray(result.error.details, ({ type }) => type === "object.unknown"); const [actualErrors, unknownDetails] = array.bifurcate(result.error.details, ({ type }) => type === "object.unknown");
if (unknownDetails.length > 0) { if (unknownDetails.length > 0) {
console.warn("HelmChart data has unexpected fields", { original: data, unknownFields: unknownDetails.flatMap(d => d.path) }); console.warn("HelmChart data has unexpected fields", { original: data, unknownFields: unknownDetails.flatMap(d => d.path) });

View File

@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { RawHelmChart } from "../helm-charts.api"; import type { RawHelmChart } from "../helm-charts.api";
import { HelmChart } from "../helm-charts.api"; import { HelmChart } from "../helm-charts.api";
import { isDefined } from "../../../utils"; import { isDefined } from "@k8slens/utilities";
import apiBaseInjectable from "../../api-base.injectable"; import apiBaseInjectable from "../../api-base.injectable";
export type RequestHelmCharts = () => Promise<HelmChart[]>; export type RequestHelmCharts = () => Promise<HelmChart[]>;

View File

@ -3,13 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { AsyncResult } from "../../../utils/async-result"; import type { AsyncResult } from "@k8slens/utilities";
import { urlBuilderFor } from "../../../utils/buildUrl"; import { urlBuilderFor } from "@k8slens/utilities";
import apiBaseInjectable from "../../api-base.injectable"; import apiBaseInjectable from "../../api-base.injectable";
const requestReadmeEndpoint = urlBuilderFor("/v2/charts/:repo/:name/readme"); const requestReadmeEndpoint = urlBuilderFor("/v2/charts/:repo/:name/readme");
export type RequestHelmChartReadme = (repo: string, name: string, version?: string) => Promise<AsyncResult<string>>; export type RequestHelmChartReadme = (repo: string, name: string, version?: string) => AsyncResult<string>;
const requestHelmChartReadmeInjectable = getInjectable({ const requestHelmChartReadmeInjectable = getInjectable({
id: "request-helm-chart-readme", id: "request-helm-chart-readme",

View File

@ -3,13 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { AsyncResult } from "../../../utils/async-result"; import type { AsyncResult } from "@k8slens/utilities";
import { urlBuilderFor } from "../../../utils/buildUrl"; import { urlBuilderFor } from "@k8slens/utilities";
import apiBaseInjectable from "../../api-base.injectable"; import apiBaseInjectable from "../../api-base.injectable";
const requestValuesEndpoint = urlBuilderFor("/v2/charts/:repo/:name/values"); const requestValuesEndpoint = urlBuilderFor("/v2/charts/:repo/:name/values");
export type RequestHelmChartValues = (repo: string, name: string, version: string) => Promise<AsyncResult<string>>; export type RequestHelmChartValues = (repo: string, name: string, version: string) => AsyncResult<string>;
const requestHelmChartValuesInjectable = getInjectable({ const requestHelmChartValuesInjectable = getInjectable({
id: "request-helm-chart-values", id: "request-helm-chart-values",

View File

@ -3,10 +3,10 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { urlBuilderFor } from "../../../utils/buildUrl"; import { urlBuilderFor } from "@k8slens/utilities/src/buildUrl";
import { HelmChart } from "../helm-charts.api"; import { HelmChart } from "../helm-charts.api";
import type { RawHelmChart } from "../helm-charts.api"; import type { RawHelmChart } from "../helm-charts.api";
import { isDefined } from "../../../utils"; import { isDefined } from "@k8slens/utilities";
import apiBaseInjectable from "../../api-base.injectable"; import apiBaseInjectable from "../../api-base.injectable";
const requestVersionsEndpoint = urlBuilderFor("/v2/charts/:repo/:name/versions"); const requestVersionsEndpoint = urlBuilderFor("/v2/charts/:repo/:name/versions");

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { urlBuilderFor } from "../../../utils/buildUrl"; import { urlBuilderFor } from "@k8slens/utilities/src/buildUrl";
import apiBaseInjectable from "../../api-base.injectable"; import apiBaseInjectable from "../../api-base.injectable";
export type RequestHelmReleaseConfiguration = ( export type RequestHelmReleaseConfiguration = (

View File

@ -5,7 +5,7 @@
import yaml from "js-yaml"; import yaml from "js-yaml";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { HelmReleaseUpdateDetails } from "../helm-releases.api"; import type { HelmReleaseUpdateDetails } from "../helm-releases.api";
import { urlBuilderFor } from "../../../utils/buildUrl"; import { urlBuilderFor } from "@k8slens/utilities/src/buildUrl";
import apiBaseInjectable from "../../api-base.injectable"; import apiBaseInjectable from "../../api-base.injectable";
interface HelmReleaseCreatePayload { interface HelmReleaseCreatePayload {

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { urlBuilderFor } from "../../../utils/buildUrl"; import { urlBuilderFor } from "@k8slens/utilities/src/buildUrl";
import apiBaseInjectable from "../../api-base.injectable"; import apiBaseInjectable from "../../api-base.injectable";
export type RequestDeleteHelmRelease = (name: string, namespace: string) => Promise<void>; export type RequestDeleteHelmRelease = (name: string, namespace: string) => Promise<void>;

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { KubeJsonApiData } from "../../kube-json-api"; import type { KubeJsonApiData } from "../../kube-json-api";
import { urlBuilderFor } from "../../../utils/buildUrl"; import { urlBuilderFor } from "@k8slens/utilities/src/buildUrl";
import apiBaseInjectable from "../../api-base.injectable"; import apiBaseInjectable from "../../api-base.injectable";
export interface HelmReleaseDetails { export interface HelmReleaseDetails {

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { urlBuilderFor } from "../../../utils/buildUrl"; import { urlBuilderFor } from "@k8slens/utilities/src/buildUrl";
import apiBaseInjectable from "../../api-base.injectable"; import apiBaseInjectable from "../../api-base.injectable";
export interface HelmReleaseRevision { export interface HelmReleaseRevision {

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { urlBuilderFor } from "../../../utils/buildUrl"; import { urlBuilderFor } from "@k8slens/utilities/src/buildUrl";
import apiBaseInjectable from "../../api-base.injectable"; import apiBaseInjectable from "../../api-base.injectable";
import type { HelmReleaseDto } from "../helm-releases.api"; import type { HelmReleaseDto } from "../helm-releases.api";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { urlBuilderFor } from "../../../utils/buildUrl"; import { urlBuilderFor } from "@k8slens/utilities/src/buildUrl";
import apiBaseInjectable from "../../api-base.injectable"; import apiBaseInjectable from "../../api-base.injectable";
export type RequestHelmReleaseRollback = (name: string, namespace: string, revision: number) => Promise<void>; export type RequestHelmReleaseRollback = (name: string, namespace: string, revision: number) => Promise<void>;

View File

@ -3,8 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { urlBuilderFor } from "../../../utils/buildUrl"; import { urlBuilderFor } from "@k8slens/utilities/src/buildUrl";
import type { AsyncResult } from "../../../utils/async-result"; import type { AsyncResult } from "@k8slens/utilities";
import apiBaseInjectable from "../../api-base.injectable"; import apiBaseInjectable from "../../api-base.injectable";
interface HelmReleaseUpdatePayload { interface HelmReleaseUpdatePayload {
@ -18,7 +18,7 @@ export type RequestHelmReleaseUpdate = (
name: string, name: string,
namespace: string, namespace: string,
payload: HelmReleaseUpdatePayload payload: HelmReleaseUpdatePayload
) => Promise<AsyncResult<void, unknown>>; ) => AsyncResult<void, unknown>;
const requestUpdateEndpoint = urlBuilderFor("/v2/releases/:namespace/:name"); const requestUpdateEndpoint = urlBuilderFor("/v2/releases/:namespace/:name");

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { urlBuilderFor } from "../../../utils/buildUrl"; import { urlBuilderFor } from "@k8slens/utilities/src/buildUrl";
import apiBaseInjectable from "../../api-base.injectable"; import apiBaseInjectable from "../../api-base.injectable";
export type RequestHelmReleaseValues = (name: string, namespace: string, all?: boolean) => Promise<string>; export type RequestHelmReleaseValues = (name: string, namespace: string, all?: boolean) => Promise<string>;

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { OptionVarient } from "../../utils"; import type { OptionVariant } from "@k8slens/utilities";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api"; import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import type { BaseKubeObjectCondition, LabelSelector, NamespaceScopedMetadata } from "../kube-object"; import type { BaseKubeObjectCondition, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
@ -46,7 +46,7 @@ export interface V2Beta1ContainerResourceMetricSource {
targetAverageValue?: string; targetAverageValue?: string;
} }
export type ContainerResourceMetricSource = export type ContainerResourceMetricSource =
| V2ContainerResourceMetricSource | V2ContainerResourceMetricSource
| V2Beta1ContainerResourceMetricSource; | V2Beta1ContainerResourceMetricSource;
@ -74,7 +74,7 @@ export interface V2Beta1ExternalMetricSource {
}; };
} }
export type ExternalMetricSource = export type ExternalMetricSource =
| V2Beta1ExternalMetricSource | V2Beta1ExternalMetricSource
| V2ExternalMetricSource; | V2ExternalMetricSource;
@ -152,11 +152,11 @@ export interface BaseHorizontalPodAutoscalerMetricSpec {
} }
export type HorizontalPodAutoscalerMetricSpec = export type HorizontalPodAutoscalerMetricSpec =
| OptionVarient<HpaMetricType.Resource, BaseHorizontalPodAutoscalerMetricSpec, "resource"> | OptionVariant<HpaMetricType.Resource, BaseHorizontalPodAutoscalerMetricSpec, "resource">
| OptionVarient<HpaMetricType.External, BaseHorizontalPodAutoscalerMetricSpec, "external"> | OptionVariant<HpaMetricType.External, BaseHorizontalPodAutoscalerMetricSpec, "external">
| OptionVarient<HpaMetricType.Object, BaseHorizontalPodAutoscalerMetricSpec, "object"> | OptionVariant<HpaMetricType.Object, BaseHorizontalPodAutoscalerMetricSpec, "object">
| OptionVarient<HpaMetricType.Pods, BaseHorizontalPodAutoscalerMetricSpec, "pods"> | OptionVariant<HpaMetricType.Pods, BaseHorizontalPodAutoscalerMetricSpec, "pods">
| OptionVarient<HpaMetricType.ContainerResource, BaseHorizontalPodAutoscalerMetricSpec, "containerResource">; | OptionVariant<HpaMetricType.ContainerResource, BaseHorizontalPodAutoscalerMetricSpec, "containerResource">;
interface HorizontalPodAutoscalerBehavior { interface HorizontalPodAutoscalerBehavior {
scaleUp?: HPAScalingRules; scaleUp?: HPAScalingRules;
@ -294,11 +294,11 @@ export interface BaseHorizontalPodAutoscalerMetricStatus {
} }
export type HorizontalPodAutoscalerMetricStatus = export type HorizontalPodAutoscalerMetricStatus =
| OptionVarient<HpaMetricType.Resource, BaseHorizontalPodAutoscalerMetricStatus, "resource"> | OptionVariant<HpaMetricType.Resource, BaseHorizontalPodAutoscalerMetricStatus, "resource">
| OptionVarient<HpaMetricType.External, BaseHorizontalPodAutoscalerMetricStatus, "external"> | OptionVariant<HpaMetricType.External, BaseHorizontalPodAutoscalerMetricStatus, "external">
| OptionVarient<HpaMetricType.Object, BaseHorizontalPodAutoscalerMetricStatus, "object"> | OptionVariant<HpaMetricType.Object, BaseHorizontalPodAutoscalerMetricStatus, "object">
| OptionVarient<HpaMetricType.Pods, BaseHorizontalPodAutoscalerMetricStatus, "pods"> | OptionVariant<HpaMetricType.Pods, BaseHorizontalPodAutoscalerMetricStatus, "pods">
| OptionVarient<HpaMetricType.ContainerResource, BaseHorizontalPodAutoscalerMetricStatus, "containerResource">; | OptionVariant<HpaMetricType.ContainerResource, BaseHorizontalPodAutoscalerMetricStatus, "containerResource">;
export interface HorizontalPodAutoscalerSpec { export interface HorizontalPodAutoscalerSpec {
scaleTargetRef: CrossVersionObjectReference; scaleTargetRef: CrossVersionObjectReference;

View File

@ -5,7 +5,7 @@
import type { NamespaceScopedMetadata, TypedLocalObjectReference } from "../kube-object"; import type { NamespaceScopedMetadata, TypedLocalObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import { hasTypedProperty, isString, iter } from "../../utils"; import { hasTypedProperty, isString, iter } from "@k8slens/utilities";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api"; import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import type { RequireExactlyOne } from "type-fest"; import type { RequireExactlyOne } from "type-fest";

View File

@ -6,7 +6,7 @@
// Metrics api // Metrics api
import moment from "moment"; import moment from "moment";
import { isDefined, object } from "../../utils"; import { isDefined, object } from "@k8slens/utilities";
export interface MetricData { export interface MetricData {
status: string; status: string;

View File

@ -5,7 +5,7 @@
import type { BaseKubeObjectCondition, ClusterScopedMetadata } from "../kube-object"; import type { BaseKubeObjectCondition, ClusterScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import { cpuUnitsToNumber, unitsToBytes, isObject } from "../../../renderer/utils"; import { cpuUnitsToNumber, unitsToBytes, isObject } from "@k8slens/utilities";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api"; import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import { TypedRegEx } from "typed-regex"; import { TypedRegEx } from "typed-regex";

View File

@ -8,7 +8,7 @@ import { KubeObject } from "../kube-object";
import type { Pod } from "./pod.api"; import type { Pod } from "./pod.api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api"; import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import { object } from "../../utils"; import { object } from "@k8slens/utilities";
import type { ResourceRequirements } from "./types/resource-requirements"; import type { ResourceRequirements } from "./types/resource-requirements";
export class PersistentVolumeClaimApi extends KubeApi<PersistentVolumeClaim> { export class PersistentVolumeClaimApi extends KubeApi<PersistentVolumeClaim> {

View File

@ -5,7 +5,7 @@
import type { ClusterScopedMetadata, LabelSelector, ObjectReference, TypedLocalObjectReference } from "../kube-object"; import type { ClusterScopedMetadata, LabelSelector, ObjectReference, TypedLocalObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import { unitsToBytes } from "../../utils"; import { unitsToBytes } from "@k8slens/utilities";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api"; import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import type { ResourceRequirements } from "./types/resource-requirements"; import type { ResourceRequirements } from "./types/resource-requirements";

View File

@ -10,7 +10,7 @@ import type { KubeObjectMetadata, LocalObjectReference, Affinity, Toleration, Na
import type { SecretReference } from "./secret.api"; import type { SecretReference } from "./secret.api";
import type { PersistentVolumeClaimSpec } from "./persistent-volume-claim.api"; import type { PersistentVolumeClaimSpec } from "./persistent-volume-claim.api";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import { isDefined } from "../../utils"; import { isDefined } from "@k8slens/utilities";
import type { PodSecurityContext } from "./types/pod-security-context"; import type { PodSecurityContext } from "./types/pod-security-context";
import type { Probe } from "./types/probe"; import type { Probe } from "./types/probe";
import type { Container } from "./types/container"; import type { Container } from "./types/container";

View File

@ -5,10 +5,10 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { Patch } from "rfc6902"; import type { Patch } from "rfc6902";
import apiBaseInjectable from "../../api-base.injectable"; import apiBaseInjectable from "../../api-base.injectable";
import type { AsyncResult } from "../../../utils/async-result"; import type { AsyncResult, Result } from "@k8slens/utilities";
import type { KubeJsonApiData } from "../../kube-json-api"; import type { KubeJsonApiData } from "../../kube-json-api";
export type RequestKubeObjectPatch = (name: string, kind: string, ns: string | undefined, patch: Patch) => Promise<AsyncResult<KubeJsonApiData, string>>; export type RequestKubeObjectPatch = (name: string, kind: string, ns: string | undefined, patch: Patch) => AsyncResult<KubeJsonApiData, string>;
const requestKubeObjectPatchInjectable = getInjectable({ const requestKubeObjectPatchInjectable = getInjectable({
id: "request-kube-object-patch", id: "request-kube-object-patch",
@ -23,7 +23,7 @@ const requestKubeObjectPatchInjectable = getInjectable({
ns, ns,
patch, patch,
}, },
}) as AsyncResult<string, string>; }) as Result<string, string>;
if (!result.callWasSuccessful) { if (!result.callWasSuccessful) {
return result; return result;

View File

@ -4,10 +4,10 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import apiBaseInjectable from "../../api-base.injectable"; import apiBaseInjectable from "../../api-base.injectable";
import type { AsyncResult } from "../../../utils/async-result"; import type { AsyncResult, Result } from "@k8slens/utilities";
import type { KubeJsonApiData } from "../../kube-json-api"; import type { KubeJsonApiData } from "../../kube-json-api";
export type RequestKubeObjectCreation = (resourceDescriptor: string) => Promise<AsyncResult<KubeJsonApiData, string>>; export type RequestKubeObjectCreation = (resourceDescriptor: string) => AsyncResult<KubeJsonApiData, string>;
const requestKubeObjectCreationInjectable = getInjectable({ const requestKubeObjectCreationInjectable = getInjectable({
id: "request-kube-object-creation", id: "request-kube-object-creation",
@ -15,7 +15,7 @@ const requestKubeObjectCreationInjectable = getInjectable({
const apiBase = di.inject(apiBaseInjectable); const apiBase = di.inject(apiBaseInjectable);
return async (data) => { return async (data) => {
const result = await apiBase.post("/stack", { data }) as AsyncResult<string, string>; const result = await apiBase.post("/stack", { data }) as Result<string, string>;
if (!result.callWasSuccessful) { if (!result.callWasSuccessful) {
return result; return result;

View File

@ -6,9 +6,9 @@
import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object"; import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { KubeJsonApiData } from "../kube-json-api"; import type { KubeJsonApiData } from "../kube-json-api";
import { autoBind } from "../../utils";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api"; import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import autoBind from "auto-bind";
export enum SecretType { export enum SecretType {
Opaque = "Opaque", Opaque = "Opaque",

View File

@ -3,12 +3,12 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { autoBind } from "../../utils";
import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope } from "../kube-object"; import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope } from "../kube-object";
import { KubeObject } from "../kube-object"; import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api"; import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api"; import type { KubeJsonApiData } from "../kube-json-api";
import autoBind from "auto-bind";
export interface TopologySelectorLabelRequirement { export interface TopologySelectorLabelRequirement {
key: string; key: string;

View File

@ -15,8 +15,8 @@ import type { PartialDeep, ValueOf } from "type-fest";
import { EventEmitter } from "../../common/event-emitter"; import { EventEmitter } from "../../common/event-emitter";
import type { Logger } from "../../common/logger"; import type { Logger } from "../../common/logger";
import type { Fetch } from "../fetch/fetch.injectable"; import type { Fetch } from "../fetch/fetch.injectable";
import type { Defaulted } from "../utils"; import type { Defaulted } from "@k8slens/utilities";
import { json } from "../utils"; import { isObject, isString, json } from "@k8slens/utilities";
export interface JsonApiData {} export interface JsonApiData {}
@ -184,20 +184,17 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
const res = await this.dependencies.fetch(reqUrl, reqInit); const res = await this.dependencies.fetch(reqUrl, reqInit);
return this.parseResponse<OutData>(res, infoLog); return await this.parseResponse(res, infoLog) as OutData;
} }
protected async parseResponse<OutData>(res: Response, log: JsonApiLog): Promise<OutData> { protected async parseResponse(res: Response, log: JsonApiLog): Promise<Data> {
const { status } = res; const { status } = res;
const text = await res.text(); const text = await res.text();
let data: any; const parseResponse = json.parse(text || "{}");
const data = parseResponse.callWasSuccessful
try { ? parseResponse.response as Data
data = text ? json.parse(text) : ""; // DELETE-requests might not have response-body : text as Data;
} catch (e) {
data = text;
}
if (status >= 200 && status < 300) { if (status >= 200 && status < 300) {
this.onData.emit(data, res); this.onData.emit(data, res);
@ -211,7 +208,7 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
throw data; throw data;
} }
const error = new JsonApiErrorParsed(data, this.parseError(data, res)); const error = new JsonApiErrorParsed(data as JsonApiError, this.parseError(data, res));
this.onError.emit(error, res); this.onError.emit(error, res);
this.writeLog({ ...log, error }); this.writeLog({ ...log, error });
@ -219,16 +216,20 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
throw error; throw error;
} }
protected parseError(error: JsonApiError | string, res: Response): string[] { protected parseError(error: unknown, res: Response): string[] {
if (typeof error === "string") { if (isString(error)) {
return [error]; return [error];
} }
if (!isObject(error)) {
return [];
}
if (Array.isArray(error.errors)) { if (Array.isArray(error.errors)) {
return error.errors.map(error => error.title); return error.errors.map(error => error.title);
} }
if (error.message) { if (isString(error.message)) {
return [error.message]; return [error.message];
} }

View File

@ -5,7 +5,7 @@
// Parse kube-api path and get api-version, group, etc. // Parse kube-api path and get api-version, group, etc.
import { splitArray } from "../utils"; import { array } from "@k8slens/utilities";
export interface IKubeApiLinkRef { export interface IKubeApiLinkRef {
apiPrefix?: string; apiPrefix?: string;
@ -26,7 +26,7 @@ export function parseKubeApi(path: string): IKubeApiParsed {
const apiPath = new URL(path, "https://localhost").pathname; const apiPath = new URL(path, "https://localhost").pathname;
const [, prefix, ...parts] = apiPath.split("/"); const [, prefix, ...parts] = apiPath.split("/");
const apiPrefix = `/${prefix}`; const apiPrefix = `/${prefix}`;
const [left, right, namespaced] = splitArray(parts, "namespaces"); const [left, right, namespaced] = array.split(parts, "namespaces");
let apiGroup!: string; let apiGroup!: string;
let apiVersion!: string; let apiVersion!: string;
let namespace!: string; let namespace!: string;

View File

@ -13,8 +13,8 @@ import { KubeObject, KubeStatus, isKubeStatusData } from "./kube-object";
import byline from "byline"; import byline from "byline";
import type { IKubeWatchEvent } from "./kube-watch-event"; import type { IKubeWatchEvent } from "./kube-watch-event";
import type { KubeJsonApiData, KubeJsonApi } from "./kube-json-api"; import type { KubeJsonApiData, KubeJsonApi } from "./kube-json-api";
import type { Disposer } from "../utils"; import type { Disposer } from "@k8slens/utilities";
import { isDefined, noop, WrappedAbortController } from "../utils"; import { isDefined, noop, WrappedAbortController } from "@k8slens/utilities";
import type { RequestInit, Response } from "@k8slens/node-fetch"; import type { RequestInit, Response } from "@k8slens/node-fetch";
import type { Patch } from "rfc6902"; import type { Patch } from "rfc6902";
import assert from "assert"; import assert from "assert";

View File

@ -4,8 +4,8 @@
*/ */
import { action, computed, makeObservable, observable, reaction } from "mobx"; import { action, computed, makeObservable, observable, reaction } from "mobx";
import type { Disposer } from "../utils"; import type { Disposer } from "@k8slens/utilities";
import { waitUntilDefined, autoBind, includes, rejectPromiseBy } from "../utils"; import { waitUntilDefined, includes, rejectPromiseBy, object } from "@k8slens/utilities";
import type { KubeJsonApiDataFor, KubeObject } from "./kube-object"; import type { KubeJsonApiDataFor, KubeObject } from "./kube-object";
import { KubeStatus } from "./kube-object"; import { KubeStatus } from "./kube-object";
import type { IKubeWatchEvent } from "./kube-watch-event"; import type { IKubeWatchEvent } from "./kube-watch-event";
@ -17,9 +17,9 @@ import type { Patch } from "rfc6902";
import type { Logger } from "../logger"; import type { Logger } from "../logger";
import assert from "assert"; import assert from "assert";
import type { PartialDeep } from "type-fest"; import type { PartialDeep } from "type-fest";
import { entries } from "../utils/objects";
import AbortController from "abort-controller"; import AbortController from "abort-controller";
import type { ClusterContext } from "../../renderer/cluster-frame-context/cluster-frame-context"; import type { ClusterContext } from "../../renderer/cluster-frame-context/cluster-frame-context";
import autoBind from "auto-bind";
export type OnLoadFailure = (error: unknown) => void; export type OnLoadFailure = (error: unknown) => void;
@ -179,7 +179,7 @@ export abstract class KubeObjectStore<
return this.items.filter((item: K) => { return this.items.filter((item: K) => {
const itemLabels = item.metadata.labels || {}; const itemLabels = item.metadata.labels || {};
return entries(labels) return object.entries(labels)
.every(([key, value]) => itemLabels[key] === value); .every(([key, value]) => itemLabels[key] === value);
}); });
} }

View File

@ -7,7 +7,7 @@
import moment from "moment"; import moment from "moment";
import type { KubeJsonApiData, KubeJsonApiDataList, KubeJsonApiListMetadata } from "./kube-json-api"; import type { KubeJsonApiData, KubeJsonApiDataList, KubeJsonApiListMetadata } from "./kube-json-api";
import { autoBind, formatDuration, hasOptionalTypedProperty, hasTypedProperty, isObject, isString, isNumber, bindPredicate, isTypedArray, isRecord, json } from "../utils"; import { formatDuration, hasOptionalTypedProperty, hasTypedProperty, isObject, isString, isNumber, bindPredicate, isTypedArray, isRecord } from "@k8slens/utilities";
import type { ItemObject } from "../item.store"; import type { ItemObject } from "../item.store";
import type { Patch } from "rfc6902"; import type { Patch } from "rfc6902";
import assert from "assert"; import assert from "assert";
@ -17,6 +17,7 @@ import { apiKubeInjectionToken } from "./api-kube";
import requestKubeObjectCreationInjectable from "./endpoints/resource-applier.api/request-update.injectable"; import requestKubeObjectCreationInjectable from "./endpoints/resource-applier.api/request-update.injectable";
import { dump } from "js-yaml"; import { dump } from "js-yaml";
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import autoBind from "auto-bind";
export type KubeJsonApiDataFor<K> = K extends KubeObject<infer Metadata, infer Status, infer Spec> export type KubeJsonApiDataFor<K> = K extends KubeObject<infer Metadata, infer Status, infer Spec>
? KubeJsonApiData<Metadata, Status, Spec> ? KubeJsonApiData<Metadata, Status, Spec>
@ -624,7 +625,7 @@ export class KubeObject<
} }
toPlainObject() { toPlainObject() {
return json.parse(JSON.stringify(this)) as JsonObject; return JSON.parse(JSON.stringify(this)) as JsonObject;
} }
/** /**

View File

@ -7,13 +7,13 @@ import type { KubernetesCluster } from "../catalog-entities";
import yaml from "js-yaml"; import yaml from "js-yaml";
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import productNameInjectable from "../vars/product-name.injectable"; import productNameInjectable from "../vars/product-name.injectable";
import type { AsyncResult } from "../utils/async-result"; import type { AsyncResult } from "@k8slens/utilities";
import type { Logger } from "../logger"; import type { Logger } from "../logger";
import type { KubectlApplyAll, KubectlDeleteAll } from "../kube-helpers/channels"; import type { KubectlApplyAll, KubectlDeleteAll } from "../kube-helpers/channels";
import type { ReadDirectory } from "../fs/read-directory.injectable"; import type { ReadDirectory } from "../fs/read-directory.injectable";
import type { JoinPaths } from "../path/join-paths.injectable"; import type { JoinPaths } from "../path/join-paths.injectable";
import type { ReadFile } from "../fs/read-file.injectable"; import type { ReadFile } from "../fs/read-file.injectable";
import { hasTypedProperty, isObject } from "../utils"; import { hasTypedProperty, isObject } from "@k8slens/utilities";
export interface ResourceApplyingStack { export interface ResourceApplyingStack {
kubectlApplyFolder(folderPath: string, templateContext?: any, extraArgs?: string[]): Promise<string>; kubectlApplyFolder(folderPath: string, templateContext?: any, extraArgs?: string[]): Promise<string>;

View File

@ -7,7 +7,7 @@ import { KubeConfig } from "@kubernetes/client-node";
import yaml from "js-yaml"; import yaml from "js-yaml";
import type { Cluster, Context, User } from "@kubernetes/client-node/dist/config_types"; import type { Cluster, Context, User } from "@kubernetes/client-node/dist/config_types";
import { newClusters, newContexts, newUsers } from "@kubernetes/client-node/dist/config_types"; import { newClusters, newContexts, newUsers } from "@kubernetes/client-node/dist/config_types";
import { isDefined } from "./utils"; import { isDefined } from "@k8slens/utilities";
import Joi from "joi"; import Joi from "joi";
import type { PartialDeep } from "type-fest"; import type { PartialDeep } from "type-fest";

View File

@ -7,7 +7,7 @@ import { getInjectionToken } from "@ogre-tools/injectable";
import type { Asyncify } from "type-fest"; import type { Asyncify } from "type-fest";
import type { RequestChannelHandler } from "../../main/utils/channel/channel-listeners/listener-tokens"; import type { RequestChannelHandler } from "../../main/utils/channel/channel-listeners/listener-tokens";
import type { ClusterId } from "../cluster-types"; import type { ClusterId } from "../cluster-types";
import type { AsyncResult } from "../utils/async-result"; import type { AsyncResult } from "@k8slens/utilities";
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token"; import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
export interface KubectlApplyAllArgs { export interface KubectlApplyAllArgs {

View File

@ -2,7 +2,7 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getGlobalOverrideForFunction } from "./test-utils/get-global-override-for-function"; import { getGlobalOverrideForFunction } from "@k8slens/test-utils";
import logErrorInjectable from "./log-error.injectable"; import logErrorInjectable from "./log-error.injectable";
// Note: this should remain as it is, and throw if called. Logging error is something // Note: this should remain as it is, and throw if called. Logging error is something

View File

@ -4,13 +4,12 @@
*/ */
import loggerInjectable from "./logger.injectable"; import loggerInjectable from "./logger.injectable";
import { getGlobalOverride } from "./test-utils/get-global-override"; import { getGlobalOverride } from "@k8slens/test-utils";
import { noop } from "./utils";
export default getGlobalOverride(loggerInjectable, () => ({ export default getGlobalOverride(loggerInjectable, () => ({
warn: noop, warn: () => {},
debug: noop, debug: () => {},
error: noop, error: () => {},
info: noop, info: () => {},
silly: noop, silly: () => {},
})); }));

View File

@ -6,7 +6,7 @@
import type { match } from "react-router"; import type { match } from "react-router";
import { matchPath } from "react-router"; import { matchPath } from "react-router";
import { countBy } from "lodash"; import { countBy } from "lodash";
import { isDefined, iter } from "../utils"; import { isDefined, iter } from "@k8slens/utilities";
import { pathToRegexp } from "path-to-regexp"; import { pathToRegexp } from "path-to-regexp";
import type Url from "url-parse"; import type Url from "url-parse";
import { RoutingError, RoutingErrorType } from "./error"; import { RoutingError, RoutingErrorType } from "./error";

View File

@ -5,7 +5,7 @@
import fse from "fs-extra"; import fse from "fs-extra";
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable"; import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
import { isErrnoException } from "../utils"; import { isErrnoException } from "@k8slens/utilities";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import joinPathsInjectable from "../path/join-paths.injectable"; import joinPathsInjectable from "../path/join-paths.injectable";

View File

@ -6,7 +6,7 @@
import { action, observable, makeObservable, isObservableArray, isObservableSet, isObservableMap } from "mobx"; import { action, observable, makeObservable, isObservableArray, isObservableSet, isObservableMap } from "mobx";
import type { BaseStoreDependencies } from "../base-store/base-store"; import type { BaseStoreDependencies } from "../base-store/base-store";
import { BaseStore } from "../base-store/base-store"; import { BaseStore } from "../base-store/base-store";
import { getOrInsertSet, toggle, toJS, object } from "../../renderer/utils"; import { getOrInsertSet, toggle, object } from "@k8slens/utilities";
import type { UserPreferencesModel, StoreType } from "./preferences-helpers"; import type { UserPreferencesModel, StoreType } from "./preferences-helpers";
import type { EmitAppEvent } from "../app-event-bus/emit-event.injectable"; import type { EmitAppEvent } from "../app-event-bus/emit-event.injectable";
@ -14,6 +14,7 @@ import type { EmitAppEvent } from "../app-event-bus/emit-event.injectable";
import type { SelectedUpdateChannel } from "../../features/application-update/common/selected-update-channel/selected-update-channel.injectable"; import type { SelectedUpdateChannel } from "../../features/application-update/common/selected-update-channel/selected-update-channel.injectable";
import type { ReleaseChannel } from "../../features/application-update/common/update-channels"; import type { ReleaseChannel } from "../../features/application-update/common/update-channels";
import type { PreferenceDescriptors } from "./preference-descriptors.injectable"; import type { PreferenceDescriptors } from "./preference-descriptors.injectable";
import { toJS } from "../utils";
export interface UserStoreModel { export interface UserStoreModel {
preferences: UserPreferencesModel; preferences: UserPreferencesModel;

View File

@ -1,68 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { join, nth, reduce, concat } from "@k8slens/utilities/src/iter";
describe("iter", () => {
describe("reduce", () => {
it("can reduce a value", () => {
expect(reduce([1, 2, 3], (acc: number[], current: number) => [current, ...acc], [0])).toEqual([3, 2, 1, 0]);
});
it("can reduce an empty iterable", () => {
expect(reduce([], (acc: number[], current: number) => [acc[0] + current], [])).toEqual([]);
});
});
describe("join", () => {
it("should not prefix the output by the seperator", () => {
expect(join(["a", "b", "c"].values(), " ")).toBe("a b c");
});
it("should return empty string if iterator is empty", () => {
expect(join([].values(), " ")).toBe("");
});
it("should return just first entry if iterator is of size 1", () => {
expect(join(["d"].values(), " ")).toBe("d");
});
});
describe("nth", () => {
it("should return undefined past the end of the iterator", () => {
expect(nth(["a"], 123)).toBeUndefined();
});
it("should by 0-indexing the index", () => {
expect(nth(["a", "b"], 0)).toBe("a");
});
});
describe("concat", () => {
it("should yield undefined for empty args", () => {
const iter = concat();
expect(iter.next()).toEqual({ done: true });
});
it("should yield undefined for only empty args", () => {
const iter = concat([].values(), [].values(), [].values(), [].values());
expect(iter.next()).toEqual({ done: true });
});
it("should yield all of the first and then all of the second", () => {
const iter = concat([1, 2, 3].values(), [4, 5, 6].values());
expect(iter.next()).toEqual({ done: false, value: 1 });
expect(iter.next()).toEqual({ done: false, value: 2 });
expect(iter.next()).toEqual({ done: false, value: 3 });
expect(iter.next()).toEqual({ done: false, value: 4 });
expect(iter.next()).toEqual({ done: false, value: 5 });
expect(iter.next()).toEqual({ done: false, value: 6 });
expect(iter.next()).toEqual({ done: true });
});
});
});

View File

@ -1,39 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { nFircate } from "../n-fircate";
describe("nFircate", () => {
it("should produce an empty array if no parts are provided", () => {
expect(nFircate([{ a: 1 }, { a: 2 }], "a", []).length).toBe(0);
});
it("should ignore non-matching parts", () => {
const res = nFircate([{ a: 1 }, { a: 2 }], "a", [1]);
expect(res.length).toBe(1);
expect(res[0].length).toBe(1);
});
it("should include all matching parts in each type", () => {
const res = nFircate([{ a: 1, b: "a" }, { a: 2, b: "b" }, { a: 1, b: "c" }], "a", [1, 2]);
expect(res.length).toBe(2);
expect(res[0].length).toBe(2);
expect(res[0][0].b).toBe("a");
expect(res[0][1].b).toBe("c");
expect(res[1].length).toBe(1);
expect(res[1][0].b).toBe("b");
});
it("should throw a type error if the same part is provided more than once", () => {
try {
nFircate([{ a: 1, b: "a" }, { a: 2, b: "b" }, { a: 1, b: "c" }], "a", [1, 2, 1]);
fail("Expected error");
} catch (error) {
expect(error).toBeInstanceOf(TypeError);
}
});
});

View File

@ -13,6 +13,9 @@
import * as mobx from "mobx"; import * as mobx from "mobx";
import { isObservable, observable } from "mobx"; import { isObservable, observable } from "mobx";
/**
* @deprecated Switch to doing toJS on each field instead
*/
export function toJS<T>(data: T): T { export function toJS<T>(data: T): T {
// make data observable for recursive toJS()-output // make data observable for recursive toJS()-output
if (typeof data === "object" && !isObservable(data)) { if (typeof data === "object" && !isObservable(data)) {

View File

@ -7,7 +7,7 @@ import type { ExtensionLoader } from "../extension-loader";
import extensionLoaderInjectable from "../extension-loader/extension-loader.injectable"; import extensionLoaderInjectable from "../extension-loader/extension-loader.injectable";
import { runInAction } from "mobx"; import { runInAction } from "mobx";
import updateExtensionsStateInjectable from "../extension-loader/update-extensions-state/update-extensions-state.injectable"; import updateExtensionsStateInjectable from "../extension-loader/update-extensions-state/update-extensions-state.injectable";
import { delay } from "../../renderer/utils"; import { delay } from "@k8slens/utilities";
import { getDiForUnitTesting } from "../../renderer/getDiForUnitTesting"; import { getDiForUnitTesting } from "../../renderer/getDiForUnitTesting";
import ipcRendererInjectable from "../../renderer/utils/channel/ipc-renderer.injectable"; import ipcRendererInjectable from "../../renderer/utils/channel/ipc-renderer.injectable";
import type { IpcRenderer } from "electron"; import type { IpcRenderer } from "electron";

View File

@ -8,11 +8,49 @@ import buildVersionInjectable from "../../main/vars/build-version/build-version.
import { asLegacyGlobalFunctionForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api"; import { asLegacyGlobalFunctionForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
import { getLegacyGlobalDiForExtensionApi } from "../as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import { getLegacyGlobalDiForExtensionApi } from "../as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
export { Singleton } from "../../common/utils"; export { Singleton } from "../../common/utils/singleton";
export { prevDefault, stopPropagation } from "../../renderer/utils/prevDefault";
export type { IClassName, IgnoredClassNames } from "../../renderer/utils"; export {
export { cssNames } from "../../renderer/utils/cssNames"; /**
* @deprecated Switch to using the `@k8slens/utilities` package
*/
prevDefault,
/**
* @deprecated Switch to using the `@k8slens/utilities` package
*/
stopPropagation,
/**
* @deprecated Switch to using the `@k8slens/utilities` package
*/
cssNames,
/**
* @deprecated Switch to using the `@k8slens/utilities` package
*/
disposer,
} from "@k8slens/utilities";
export type {
/**
* @deprecated Switch to using the `@k8slens/utilities` package
*/
IClassName,
/**
* @deprecated Switch to using the `@k8slens/utilities` package
*/
IgnoredClassNames,
/**
* @deprecated Switch to using the `@k8slens/utilities` package
*/
Disposer,
/**
* @deprecated Switch to using the `@k8slens/utilities` package
*/
Disposable,
/**
* @deprecated Switch to using the `@k8slens/utilities` package
*/
ExtendableDisposer,
} from "@k8slens/utilities";
export type { OpenLinkInBrowser } from "../../common/utils/open-link-in-browser.injectable"; export type { OpenLinkInBrowser } from "../../common/utils/open-link-in-browser.injectable";
@ -24,6 +62,3 @@ export const getAppVersion = () => {
return di.inject(buildVersionInjectable).get(); return di.inject(buildVersionInjectable).get();
}; };
export { disposer } from "../../common/utils";
export type { Disposer, Disposable, ExtendableDisposer } from "../../common/utils";

View File

@ -9,7 +9,7 @@ import extensionDiscoveryInjectable from "../extension-discovery/extension-disco
import type { ExtensionDiscovery } from "../extension-discovery/extension-discovery"; import type { ExtensionDiscovery } from "../extension-discovery/extension-discovery";
import installExtensionInjectable from "../install-extension/install-extension.injectable"; import installExtensionInjectable from "../install-extension/install-extension.injectable";
import directoryForUserDataInjectable from "../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable"; import directoryForUserDataInjectable from "../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
import { delay } from "../../renderer/utils"; import { delay } from "@k8slens/utilities";
import { observable, runInAction, when } from "mobx"; import { observable, runInAction, when } from "mobx";
import readJsonFileInjectable from "../../common/fs/read-json-file.injectable"; import readJsonFileInjectable from "../../common/fs/read-json-file.injectable";
import pathExistsInjectable from "../../common/fs/path-exists.injectable"; import pathExistsInjectable from "../../common/fs/path-exists.injectable";

View File

@ -7,7 +7,8 @@ import { ipcRenderer } from "electron";
import { EventEmitter } from "events"; import { EventEmitter } from "events";
import { makeObservable, observable, reaction, when } from "mobx"; import { makeObservable, observable, reaction, when } from "mobx";
import { broadcastMessage, ipcMainHandle, ipcRendererOn } from "../../common/ipc"; import { broadcastMessage, ipcMainHandle, ipcRendererOn } from "../../common/ipc";
import { isErrnoException, toJS } from "../../common/utils"; import { toJS } from "../../common/utils";
import { isErrnoException } from "@k8slens/utilities";
import type { ExtensionsStore } from "../extensions-store/extensions-store"; import type { ExtensionsStore } from "../extensions-store/extensions-store";
import type { ExtensionLoader } from "../extension-loader"; import type { ExtensionLoader } from "../extension-loader";
import type { LensExtensionId, LensExtensionManifest } from "../lens-extension"; import type { LensExtensionId, LensExtensionManifest } from "../lens-extension";

View File

@ -4,8 +4,8 @@
*/ */
import { action, computed, observable } from "mobx"; import { action, computed, observable } from "mobx";
import { disposer } from "../../renderer/utils"; import { disposer } from "@k8slens/utilities";
import type { ExtendableDisposer } from "../../renderer/utils"; import type { ExtendableDisposer } from "@k8slens/utilities";
import * as uuid from "uuid"; import * as uuid from "uuid";
import { broadcastMessage } from "../../common/ipc"; import { broadcastMessage } from "../../common/ipc";
import { ipcRenderer } from "electron"; import { ipcRenderer } from "electron";

View File

@ -6,9 +6,9 @@
import { ipcMain, ipcRenderer } from "electron"; import { ipcMain, ipcRenderer } from "electron";
import { isEqual } from "lodash"; import { isEqual } from "lodash";
import type { ObservableMap } from "mobx"; import type { ObservableMap } from "mobx";
import { action, computed, makeObservable, observable, observe, reaction, when } from "mobx"; import { action, computed, makeObservable, toJS, observable, observe, reaction, when } from "mobx";
import { broadcastMessage, ipcMainOn, ipcRendererOn, ipcMainHandle } from "../../common/ipc"; import { broadcastMessage, ipcMainOn, ipcRendererOn, ipcMainHandle } from "../../common/ipc";
import { isDefined, toJS } from "../../common/utils"; import { isDefined } from "@k8slens/utilities";
import type { InstalledExtension } from "../extension-discovery/extension-discovery"; import type { InstalledExtension } from "../extension-discovery/extension-discovery";
import type { LensExtension, LensExtensionConstructor, LensExtensionId } from "../lens-extension"; import type { LensExtension, LensExtensionConstructor, LensExtensionId } from "../lens-extension";
import type { LensExtensionState } from "../extensions-store/extensions-store"; import type { LensExtensionState } from "../extensions-store/extensions-store";

View File

@ -6,7 +6,7 @@ import type { Injectable } from "@ogre-tools/injectable";
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable"; import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { difference, find, map } from "lodash"; import { difference, find, map } from "lodash";
import { reaction, runInAction } from "mobx"; import { reaction, runInAction } from "mobx";
import { disposer } from "../../../common/utils/disposer"; import { disposer } from "@k8slens/utilities";
import type { LensExtension } from "../../lens-extension"; import type { LensExtension } from "../../lens-extension";
import { extensionRegistratorInjectionToken } from "../extension-registrator-injection-token"; import { extensionRegistratorInjectionToken } from "../extension-registrator-injection-token";
@ -43,7 +43,7 @@ const extensionInjectable = getInjectable({
reactionDisposer.push( reactionDisposer.push(
// injectables is either an array or a computed array, in which case // injectables is either an array or a computed array, in which case
// we need to update the registered injectables with a reaction every time they change // we need to update the registered injectables with a reaction every time they change
reaction( reaction(
() => Array.isArray(injectables) ? injectables : injectables.get(), () => Array.isArray(injectables) ? injectables : injectables.get(),
(currentInjectables, previousInjectables = []) => { (currentInjectables, previousInjectables = []) => {

View File

@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { getOrInsert } from "../../../common/utils"; import { getOrInsert } from "@k8slens/utilities";
import randomBytesInjectable from "../../../common/utils/random-bytes.injectable"; import randomBytesInjectable from "../../../common/utils/random-bytes.injectable";
import joinPathsInjectable from "../../../common/path/join-paths.injectable"; import joinPathsInjectable from "../../../common/path/join-paths.injectable";
import directoryForExtensionDataInjectable from "./directory-for-extension-data.injectable"; import directoryForExtensionDataInjectable from "./directory-for-extension-data.injectable";

View File

@ -8,7 +8,6 @@ import { action, makeObservable } from "mobx";
import type { BaseStoreDependencies } from "../../../common/base-store/base-store"; import type { BaseStoreDependencies } from "../../../common/base-store/base-store";
import { BaseStore } from "../../../common/base-store/base-store"; import { BaseStore } from "../../../common/base-store/base-store";
import type { LensExtensionId } from "../../lens-extension"; import type { LensExtensionId } from "../../lens-extension";
import { toJS } from "../../../common/utils";
import type { EnsureHashedDirectoryForExtension } from "./ensure-hashed-directory-for-extension.injectable"; import type { EnsureHashedDirectoryForExtension } from "./ensure-hashed-directory-for-extension.injectable";
interface FSProvisionModel { interface FSProvisionModel {
@ -46,8 +45,8 @@ export class FileSystemProvisionerStore extends BaseStore<FSProvisionModel> {
} }
toJSON(): FSProvisionModel { toJSON(): FSProvisionModel {
return toJS({ return {
extensions: Object.fromEntries(this.dependencies.registeredExtensions), extensions: Object.fromEntries(this.dependencies.registeredExtensions.toJSON()),
}); };
} }
} }

View File

@ -8,8 +8,8 @@ import { BaseStore } from "../common/base-store/base-store";
import * as path from "path"; import * as path from "path";
import type { LensExtension } from "./lens-extension"; import type { LensExtension } from "./lens-extension";
import assert from "assert"; import assert from "assert";
import type { StaticThis } from "../common/utils"; import type { StaticThis } from "../common/utils/singleton";
import { getOrInsertWith } from "../common/utils"; import { getOrInsertWith } from "@k8slens/utilities";
import { getLegacyGlobalDiForExtensionApi } from "./as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import { getLegacyGlobalDiForExtensionApi } from "./as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import directoryForUserDataInjectable from "../common/app-paths/directory-for-user-data/directory-for-user-data.injectable"; import directoryForUserDataInjectable from "../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
import getConfigurationFileModelInjectable from "../common/get-configuration-file-model/get-configuration-file-model.injectable"; import getConfigurationFileModelInjectable from "../common/get-configuration-file-model/get-configuration-file-model.injectable";

View File

@ -5,7 +5,6 @@
import type { LensExtensionId } from "../lens-extension"; import type { LensExtensionId } from "../lens-extension";
import { action, computed, makeObservable, observable } from "mobx"; import { action, computed, makeObservable, observable } from "mobx";
import { toJS } from "../../common/utils";
import type { BaseStoreDependencies } from "../../common/base-store/base-store"; import type { BaseStoreDependencies } from "../../common/base-store/base-store";
import { BaseStore } from "../../common/base-store/base-store"; import { BaseStore } from "../../common/base-store/base-store";
@ -57,8 +56,8 @@ export class ExtensionsStore extends BaseStore<LensExtensionsStoreModel> {
} }
toJSON(): LensExtensionsStoreModel { toJSON(): LensExtensionsStoreModel {
return toJS({ return {
extensions: Object.fromEntries(this.state), extensions: Object.fromEntries(this.state.toJSON()),
}); };
} }
} }

View File

@ -13,7 +13,7 @@ import joinPathsInjectable from "../../common/path/join-paths.injectable";
import type { PackageJson } from "../common-api"; import type { PackageJson } from "../common-api";
import writeJsonFileInjectable from "../../common/fs/write-json-file.injectable"; import writeJsonFileInjectable from "../../common/fs/write-json-file.injectable";
import { once } from "lodash"; import { once } from "lodash";
import { isErrnoException } from "../../common/utils"; import { isErrnoException } from "@k8slens/utilities";
const baseNpmInstallArgs = [ const baseNpmInstallArgs = [
"install", "install",

View File

@ -6,7 +6,7 @@ import { ipcMain } from "electron";
import { IpcPrefix, IpcRegistrar } from "./ipc-registrar"; import { IpcPrefix, IpcRegistrar } from "./ipc-registrar";
import { Disposers, lensExtensionDependencies } from "../lens-extension"; import { Disposers, lensExtensionDependencies } from "../lens-extension";
import type { LensMainExtension } from "../lens-main-extension"; import type { LensMainExtension } from "../lens-main-extension";
import type { Disposer } from "../../common/utils"; import type { Disposer } from "@k8slens/utilities";
import { once } from "lodash"; import { once } from "lodash";
import { ipcMainHandle } from "../../common/ipc"; import { ipcMainHandle } from "../../common/ipc";

View File

@ -2,7 +2,7 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { Singleton } from "../../common/utils"; import { Singleton } from "../../common/utils/singleton";
import type { LensExtension } from "../lens-extension"; import type { LensExtension } from "../lens-extension";
import { createHash } from "crypto"; import { createHash } from "crypto";
import { broadcastMessage } from "../../common/ipc"; import { broadcastMessage } from "../../common/ipc";

View File

@ -6,7 +6,7 @@ import { ipcRenderer } from "electron";
import { IpcPrefix, IpcRegistrar } from "./ipc-registrar"; import { IpcPrefix, IpcRegistrar } from "./ipc-registrar";
import { Disposers } from "../lens-extension"; import { Disposers } from "../lens-extension";
import type { LensRendererExtension } from "../lens-renderer-extension"; import type { LensRendererExtension } from "../lens-renderer-extension";
import type { Disposer } from "../../common/utils"; import type { Disposer } from "@k8slens/utilities";
import { once } from "lodash"; import { once } from "lodash";
export abstract class IpcRenderer extends IpcRegistrar { export abstract class IpcRenderer extends IpcRegistrar {

View File

@ -6,7 +6,7 @@
import type { InstalledExtension } from "./extension-discovery/extension-discovery"; import type { InstalledExtension } from "./extension-discovery/extension-discovery";
import { action, computed, makeObservable, observable } from "mobx"; import { action, computed, makeObservable, observable } from "mobx";
import type { PackageJson } from "type-fest"; import type { PackageJson } from "type-fest";
import { disposer } from "../common/utils"; import { disposer } from "@k8slens/utilities";
import type { LensExtensionDependencies } from "./lens-extension-set-dependencies"; import type { LensExtensionDependencies } from "./lens-extension-set-dependencies";
import type { ProtocolHandlerRegistration } from "../common/protocol-handler/registration"; import type { ProtocolHandlerRegistration } from "../common/protocol-handler/registration";

View File

@ -5,7 +5,7 @@
import { Disposers, LensExtension, lensExtensionDependencies } from "./lens-extension"; import { Disposers, LensExtension, lensExtensionDependencies } from "./lens-extension";
import type { CatalogEntity, CategoryFilter } from "../common/catalog"; import type { CatalogEntity, CategoryFilter } from "../common/catalog";
import type { Disposer } from "../common/utils"; import type { Disposer } from "@k8slens/utilities";
import type { EntityFilter } from "../renderer/api/catalog/entity/registry"; import type { EntityFilter } from "../renderer/api/catalog/entity/registry";
import type { TopBarRegistration } from "../renderer/components/layout/top-bar/top-bar-registration"; import type { TopBarRegistration } from "../renderer/components/layout/top-bar/top-bar-registration";
import type { KubernetesCluster } from "../common/catalog-entities"; import type { KubernetesCluster } from "../common/catalog-entities";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { powerMonitor } from "electron"; import { powerMonitor } from "electron";
import type { Disposer } from "../../common/utils/disposer"; import type { Disposer } from "@k8slens/utilities";
/** /**
* Event listener for system power events * Event listener for system power events

View File

@ -6,7 +6,7 @@
import type { CatalogCategory, CatalogEntity } from "../../common/catalog"; import type { CatalogCategory, CatalogEntity } from "../../common/catalog";
import type { CatalogEntityOnBeforeRun } from "../../renderer/api/catalog/entity/registry"; import type { CatalogEntityOnBeforeRun } from "../../renderer/api/catalog/entity/registry";
import type { Disposer } from "../../common/utils"; import type { Disposer } from "@k8slens/utilities";
import catalogCategoryRegistryInjectable from "../../common/catalog/category-registry.injectable"; import catalogCategoryRegistryInjectable from "../../common/catalog/category-registry.injectable";
import { asLegacyGlobalForExtensionApi } 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 catalogEntityRegistryInjectable from "../../renderer/api/catalog/entity/registry.injectable"; import catalogEntityRegistryInjectable from "../../renderer/api/catalog/entity/registry.injectable";

View File

@ -12,7 +12,7 @@ import navigateInjectable from "../../renderer/navigation/navigate.injectable";
import { asLegacyGlobalFunctionForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api"; import { asLegacyGlobalFunctionForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
export type { PageParamInit, PageParam } from "../../renderer/navigation/page-param"; export type { PageParamInit, PageParam } from "../../renderer/navigation/page-param";
export type { URLParams } from "../../common/utils/buildUrl"; export type { URLParams } from "@k8slens/utilities/src/buildUrl";
export const getDetailsUrl = asLegacyGlobalFunctionForExtensionApi(getDetailsUrlInjectable); export const getDetailsUrl = asLegacyGlobalFunctionForExtensionApi(getDetailsUrlInjectable);
export const showDetails = asLegacyGlobalFunctionForExtensionApi(showDetailsInjectable); export const showDetails = asLegacyGlobalFunctionForExtensionApi(showDetailsInjectable);

View File

@ -5,7 +5,7 @@
import { applicationInformationToken } from "@k8slens/application"; import { applicationInformationToken } from "@k8slens/application";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { bundledExtensionInjectionToken } from "../../../../../../common/library"; import { bundledExtensionInjectionToken } from "../../../../../../common/library";
import { object } from "../../../../../../common/utils"; import { object } from "@k8slens/utilities";
import buildSemanticVersionInjectable from "../../../../../../common/vars/build-semantic-version.injectable"; import buildSemanticVersionInjectable from "../../../../../../common/vars/build-semantic-version.injectable";
const specificVersionsInjectable = getInjectable({ const specificVersionsInjectable = getInjectable({

View File

@ -8,7 +8,7 @@ import styles from "./styles.module.scss";
import type { HTMLAttributes } from "react"; import type { HTMLAttributes } from "react";
import React, { useState } from "react"; import React, { useState } from "react";
import { Menu, MenuItem } from "../../../../../../../renderer/components/menu"; import { Menu, MenuItem } from "../../../../../../../renderer/components/menu";
import { cssNames } from "../../../../../../../renderer/utils"; import { cssNames } from "@k8slens/utilities";
import type { IconProps } from "../../../../../../../renderer/components/icon"; import type { IconProps } from "../../../../../../../renderer/components/icon";
import { Icon } from "../../../../../../../renderer/components/icon"; import { Icon } from "../../../../../../../renderer/components/icon";
import { withInjectables } from "@ogre-tools/injectable-react"; import { withInjectables } from "@ogre-tools/injectable-react";

View File

@ -3,6 +3,6 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import checkForPlatformUpdatesInjectable from "./check-for-platform-updates.injectable"; import checkForPlatformUpdatesInjectable from "./check-for-platform-updates.injectable";
import { getGlobalOverrideForFunction } from "../../../../../common/test-utils/get-global-override-for-function"; import { getGlobalOverrideForFunction } from "../../../../../../../utility-features/test-utils/src/get-global-override-for-function";
export default getGlobalOverrideForFunction(checkForPlatformUpdatesInjectable); export default getGlobalOverrideForFunction(checkForPlatformUpdatesInjectable);

Some files were not shown because too many files have changed in this diff Show More