mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix type errors after upgrade
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
377039548d
commit
642406f003
@ -31,7 +31,7 @@ export interface BaseStoreParams<T> extends ConfOptions<T> {
|
|||||||
/**
|
/**
|
||||||
* Note: T should only contain base JSON serializable types.
|
* Note: T should only contain base JSON serializable types.
|
||||||
*/
|
*/
|
||||||
export abstract class BaseStore<T> extends Singleton {
|
export abstract class BaseStore<T extends object> extends Singleton {
|
||||||
protected storeConfig?: Config<T>;
|
protected storeConfig?: Config<T>;
|
||||||
protected syncDisposers: Disposer[] = [];
|
protected syncDisposers: Disposer[] = [];
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import type { BaseStoreParams } from "../base-store";
|
|||||||
|
|
||||||
const getConfigurationFileModelInjectable = getInjectable({
|
const getConfigurationFileModelInjectable = getInjectable({
|
||||||
id: "get-configuration-file-model",
|
id: "get-configuration-file-model",
|
||||||
instantiate: () => <ConfigurationContent>(content: BaseStoreParams<ConfigurationContent>) => new Config(content),
|
instantiate: () => <T extends object>(content: BaseStoreParams<T>) => new Config(content),
|
||||||
causesSideEffects: true,
|
causesSideEffects: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import { apiBase } from "../index";
|
import { apiBase } from "../index";
|
||||||
import type { IMetricsQuery } from "../../../main/routes/metrics/metrics-query";
|
|
||||||
|
|
||||||
export interface MetricData {
|
export interface MetricData {
|
||||||
status: string;
|
status: string;
|
||||||
@ -55,28 +54,33 @@ export interface IResourceMetrics<T extends MetricData> {
|
|||||||
networkTransmit: T;
|
networkTransmit: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getMetrics(query: string, reqParams?: IMetricsReqParams): Promise<MetricData>;
|
||||||
|
async function getMetrics(query: string[], reqParams?: IMetricsReqParams): Promise<MetricData[]>;
|
||||||
|
async function getMetrics<MetricNames extends string>(query: Record<MetricNames, Partial<Record<string, string>>>, reqParams?: IMetricsReqParams): Promise<Record<MetricNames, MetricData>>;
|
||||||
|
|
||||||
|
async function getMetrics(query: string | string[] | Partial<Record<string, Partial<Record<string, string>>>>, reqParams: IMetricsReqParams = {}): Promise<MetricData | MetricData[] | Partial<Record<string, MetricData>>> {
|
||||||
|
const { range = 3600, step = 60, namespace } = reqParams;
|
||||||
|
let { start, end } = reqParams;
|
||||||
|
|
||||||
|
if (!start && !end) {
|
||||||
|
const timeNow = Date.now() / 1000;
|
||||||
|
const now = moment.unix(timeNow).startOf("minute").unix(); // round date to minutes
|
||||||
|
|
||||||
|
start = now - range;
|
||||||
|
end = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiBase.post("/metrics", {
|
||||||
|
data: query,
|
||||||
|
query: {
|
||||||
|
start, end, step,
|
||||||
|
"kubernetes_namespace": namespace,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export const metricsApi = {
|
export const metricsApi = {
|
||||||
async getMetrics<T = IMetricsQuery>(query: T, reqParams: IMetricsReqParams = {}): Promise<T extends object ? { [K in keyof T]: MetricData } : MetricData> {
|
getMetrics,
|
||||||
const { range = 3600, step = 60, namespace } = reqParams;
|
|
||||||
let { start, end } = reqParams;
|
|
||||||
|
|
||||||
if (!start && !end) {
|
|
||||||
const timeNow = Date.now() / 1000;
|
|
||||||
const now = moment.unix(timeNow).startOf("minute").unix(); // round date to minutes
|
|
||||||
|
|
||||||
start = now - range;
|
|
||||||
end = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
return apiBase.post("/metrics", {
|
|
||||||
data: query,
|
|
||||||
query: {
|
|
||||||
start, end, step,
|
|
||||||
"kubernetes_namespace": namespace,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
async getMetricProviders(): Promise<MetricProviderInfo[]> {
|
async getMetricProviders(): Promise<MetricProviderInfo[]> {
|
||||||
return apiBase.get("/metrics/providers");
|
return apiBase.get("/metrics/providers");
|
||||||
},
|
},
|
||||||
|
|||||||
@ -113,7 +113,17 @@ export abstract class LensProtocolRouter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if no exact match pick the one that is the most specific
|
// if no exact match pick the one that is the most specific
|
||||||
return matches.sort(([a], [b]) => compareMatches(a, b))[0] ?? null;
|
return matches.sort(([a], [b]) => {
|
||||||
|
if (a.path === "/") {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b.path === "/") {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return countBy(b.path)["/"] - countBy(a.path)["/"];
|
||||||
|
})[0] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -265,21 +275,3 @@ export abstract class LensProtocolRouter {
|
|||||||
this.internalRoutes.delete(urlSchema);
|
this.internalRoutes.delete(urlSchema);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* a comparison function for `array.sort(...)`. Sort order should be most path
|
|
||||||
* parts to least path parts.
|
|
||||||
* @param a the left side to compare
|
|
||||||
* @param b the right side to compare
|
|
||||||
*/
|
|
||||||
function compareMatches<T>(a: match<T>, b: match<T>): number {
|
|
||||||
if (a.path === "/") {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (b.path === "/") {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return countBy(b.path)["/"] - countBy(a.path)["/"];
|
|
||||||
}
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Readable } from "readable-stream";
|
import { Readable } from "readable-stream";
|
||||||
|
import type { ReadableStreamDefaultReadResult } from "stream/web";
|
||||||
import type { TypedArray } from "type-fest";
|
import type { TypedArray } from "type-fest";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -27,7 +27,7 @@ export class Singleton {
|
|||||||
* @param args The constructor arguments for the child class
|
* @param args The constructor arguments for the child class
|
||||||
* @returns An instance of the child class
|
* @returns An instance of the child class
|
||||||
*/
|
*/
|
||||||
static createInstance<T, R extends any[]>(this: StaticThis<T, R>, ...args: R): T {
|
static createInstance<T extends Singleton, R extends any[]>(this: StaticThis<T, R>, ...args: R): T {
|
||||||
if (!Singleton.instances.has(this)) {
|
if (!Singleton.instances.has(this)) {
|
||||||
if (Singleton.creating.length > 0) {
|
if (Singleton.creating.length > 0) {
|
||||||
throw new TypeError(`Cannot create a second singleton (${this.name}) while creating a first (${Singleton.creating})`);
|
throw new TypeError(`Cannot create a second singleton (${this.name}) while creating a first (${Singleton.creating})`);
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import type { Injectable } from "@ogre-tools/injectable";
|
|||||||
* @deprecated use asLegacyGlobalForExtensionApi instead, and use proper implementations instead of "modifications".
|
* @deprecated use asLegacyGlobalForExtensionApi instead, and use proper implementations instead of "modifications".
|
||||||
*/
|
*/
|
||||||
export const asLegacyGlobalObjectForExtensionApiWithModifications = <
|
export const asLegacyGlobalObjectForExtensionApiWithModifications = <
|
||||||
InjectableInstance extends InjectionTokenInstance,
|
InjectableInstance extends InjectionTokenInstance & object,
|
||||||
InjectionTokenInstance,
|
InjectionTokenInstance,
|
||||||
ModificationObject extends object,
|
ModificationObject extends object,
|
||||||
>(
|
>(
|
||||||
|
|||||||
@ -8,7 +8,7 @@ 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";
|
||||||
|
|
||||||
export abstract class ExtensionStore<T> extends BaseStore<T> {
|
export abstract class ExtensionStore<T extends object> extends BaseStore<T> {
|
||||||
readonly displayName = "ExtensionStore<T>";
|
readonly displayName = "ExtensionStore<T>";
|
||||||
protected extension?: LensExtension;
|
protected extension?: LensExtension;
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import type { ClusterPrometheusMetadata } from "../../../common/cluster-types";
|
|||||||
import { ClusterMetadataKey } from "../../../common/cluster-types";
|
import { ClusterMetadataKey } from "../../../common/cluster-types";
|
||||||
import logger from "../../logger";
|
import logger from "../../logger";
|
||||||
import type { Cluster } from "../../../common/cluster/cluster";
|
import type { Cluster } from "../../../common/cluster/cluster";
|
||||||
import type { IMetricsQuery } from "./metrics-query";
|
|
||||||
import { clusterRoute } from "../../router/route";
|
import { clusterRoute } from "../../router/route";
|
||||||
import { isObject } from "lodash";
|
import { isObject } from "lodash";
|
||||||
import { isRequestError } from "../../../common/utils";
|
import { isRequestError } from "../../../common/utils";
|
||||||
@ -60,7 +59,7 @@ const addMetricsRouteInjectable = getRouteInjectable({
|
|||||||
const getMetrics = di.inject(getMetricsInjectable);
|
const getMetrics = di.inject(getMetricsInjectable);
|
||||||
const loadMetrics = loadMetricsFor(getMetrics);
|
const loadMetrics = loadMetricsFor(getMetrics);
|
||||||
|
|
||||||
const queryParams: IMetricsQuery = Object.fromEntries(query.entries());
|
const queryParams = Object.fromEntries(query.entries());
|
||||||
const prometheusMetadata: ClusterPrometheusMetadata = {};
|
const prometheusMetadata: ClusterPrometheusMetadata = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
export type IMetricsQuery = string | string[] | {
|
|
||||||
[metricName: string]: string;
|
|
||||||
};
|
|
||||||
@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { reaction, when } from "mobx";
|
import { reaction, when } from "mobx";
|
||||||
|
import type { GeneralEntity } from "../../../common/catalog-entities";
|
||||||
import generalCategoryInjectable from "../../../common/catalog/categories/general.injectable";
|
import generalCategoryInjectable from "../../../common/catalog/categories/general.injectable";
|
||||||
import isActiveRouteInjectable from "../../navigation/is-route-active.injectable";
|
import isActiveRouteInjectable from "../../navigation/is-route-active.injectable";
|
||||||
import observableHistoryInjectable from "../../navigation/observable-history.injectable";
|
import observableHistoryInjectable from "../../navigation/observable-history.injectable";
|
||||||
@ -30,7 +31,7 @@ const watchForGeneralEntityNavigationInjectable = getInjectable({
|
|||||||
dispose.push(reaction(
|
dispose.push(reaction(
|
||||||
() => observableHistory.location,
|
() => observableHistory.location,
|
||||||
() => {
|
() => {
|
||||||
const entities = entityRegistry.getItemsForCategory(generalCategory);
|
const entities = entityRegistry.getItemsForCategory(generalCategory) as GeneralEntity[];
|
||||||
const activeEntity = entities.find(entity => isActiveRoute(entity.spec.path));
|
const activeEntity = entities.find(entity => isActiveRoute(entity.spec.path));
|
||||||
|
|
||||||
if (activeEntity) {
|
if (activeEntity) {
|
||||||
|
|||||||
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
import { asLegacyGlobalFunctionForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
|
import { asLegacyGlobalFunctionForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
|
||||||
import { asLegacyGlobalForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
import { asLegacyGlobalForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||||
import matchRouteInjectable from "./match-route.injectable";
|
|
||||||
import navigateInjectable from "./navigate.injectable";
|
import navigateInjectable from "./navigate.injectable";
|
||||||
import observableHistoryInjectable from "./observable-history.injectable";
|
import observableHistoryInjectable from "./observable-history.injectable";
|
||||||
|
|
||||||
@ -21,9 +20,4 @@ export const navigation = asLegacyGlobalForExtensionApi(observableHistoryInjecta
|
|||||||
*/
|
*/
|
||||||
export const navigate = asLegacyGlobalFunctionForExtensionApi(navigateInjectable);
|
export const navigate = asLegacyGlobalFunctionForExtensionApi(navigateInjectable);
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use `di.inject(matchRouteInjectable)` instead
|
|
||||||
*/
|
|
||||||
export const matchRoute = asLegacyGlobalFunctionForExtensionApi(matchRouteInjectable);
|
|
||||||
|
|
||||||
export * from "./page-param";
|
export * from "./page-param";
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import type { match, RouteProps } from "react-router";
|
|||||||
import { matchPath } from "react-router";
|
import { matchPath } from "react-router";
|
||||||
import observableHistoryInjectable from "./observable-history.injectable";
|
import observableHistoryInjectable from "./observable-history.injectable";
|
||||||
|
|
||||||
export type MatchRoute = <Params>(route: string | string[] | RouteProps) => match<Params> | null;
|
export type MatchRoute = <Params extends { [K in keyof Params]?: string }>(route: string | string[] | RouteProps) => match<Params> | null;
|
||||||
|
|
||||||
const matchRouteInjectable = getInjectable({
|
const matchRouteInjectable = getInjectable({
|
||||||
id: "match-route",
|
id: "match-route",
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import type { Draft } from "immer";
|
|||||||
import { produce, isDraft } from "immer";
|
import { produce, isDraft } from "immer";
|
||||||
import { isEqual, isPlainObject } from "lodash";
|
import { isEqual, isPlainObject } from "lodash";
|
||||||
import logger from "../../main/logger";
|
import logger from "../../main/logger";
|
||||||
|
import assert from "assert";
|
||||||
|
|
||||||
export interface StorageChange<T> {
|
export interface StorageChange<T> {
|
||||||
key: string;
|
key: string;
|
||||||
@ -154,8 +155,9 @@ export class StorageHelper<T> implements StorageLayer<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
merge(value: Partial<T> | ((draft: Draft<T>) => Partial<T> | void)) {
|
merge(value: T extends object ? Partial<T> | ((draft: Draft<T>) => Partial<T> | void) : never) {
|
||||||
const nextValue = produce<T>(toJS(this.get()), (draft) => {
|
const nextValue = produce<T>(toJS(this.get()), (draft) => {
|
||||||
|
assert(typeof draft === "object" && draft);
|
||||||
|
|
||||||
if (typeof value == "function") {
|
if (typeof value == "function") {
|
||||||
const newValue = value(draft);
|
const newValue = value(draft);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user