mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Bump typescript, @typescript-eslint/eslint-plugin, and @typescript-eslint/parser (#6143)
This commit is contained in:
1 parent
27871f57b6
commit
b0d72b78d0
16 files changed
+105
-118
No files matched your search
@@ -31,7 +31,7 @@ export interface BaseStoreParams<T> extends ConfOptions<T> {
|
||||
/**
|
||||
* 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 syncDisposers: Disposer[] = [];
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import type { BaseStoreParams } from "../base-store";
|
||||
|
||||
const getConfigurationFileModelInjectable = getInjectable({
|
||||
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,
|
||||
});
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
import moment from "moment";
|
||||
import { apiBase } from "../index";
|
||||
import type { IMetricsQuery } from "../../../main/routes/metrics/metrics-query";
|
||||
|
||||
export interface MetricData {
|
||||
status: string;
|
||||
@@ -55,28 +54,33 @@ export interface IResourceMetrics<T extends MetricData> {
|
||||
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 = {
|
||||
async getMetrics<T = IMetricsQuery>(query: T, reqParams: IMetricsReqParams = {}): Promise<T extends object ? { [K in keyof T]: MetricData } : 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,
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
getMetrics,
|
||||
async getMetricProviders(): Promise<MetricProviderInfo[]> {
|
||||
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
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 type { ReadableStreamDefaultReadResult } from "stream/web";
|
||||
import type { TypedArray } from "type-fest";
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,7 +27,7 @@ export class Singleton {
|
||||
* @param args The constructor arguments for 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.creating.length > 0) {
|
||||
throw new TypeError(`Cannot create a second singleton (${this.name}) while creating a first (${Singleton.creating})`);
|
||||
|
||||
Reference in new issue
Block a user