mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix type errors
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
cb538bf716
commit
b5178c7cdf
@ -6,7 +6,6 @@ import { disposer, isPromiseLike } from "@k8slens/utilities";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type Conf from "conf/dist/source";
|
||||
import type { Options } from "conf/dist/source";
|
||||
import type { Migrations } from "conf/dist/source/types";
|
||||
import { isEqual, kebabCase } from "lodash";
|
||||
import type { IEqualsComparer } from "mobx";
|
||||
import { reaction } from "mobx";
|
||||
@ -20,6 +19,7 @@ import type { MessageChannel } from "@k8slens/messaging";
|
||||
import { persistentStorageIpcChannelPrefixesInjectionToken } from "./channel-prefix";
|
||||
import { shouldPersistentStorageDisableSyncInIpcListenerInjectionToken } from "./disable-sync";
|
||||
import { persistStateToConfigInjectionToken } from "./save-to-file";
|
||||
import type { Migrations } from "./migrations.injectable";
|
||||
|
||||
export interface PersistentStorage {
|
||||
/**
|
||||
@ -30,13 +30,12 @@ export interface PersistentStorage {
|
||||
}
|
||||
|
||||
export interface PersistentStorageParams<T extends object> extends Omit<Options<T>, "migrations"> {
|
||||
syncOptions?: {
|
||||
fireImmediately?: boolean;
|
||||
readonly syncOptions?: {
|
||||
readonly fireImmediately?: boolean;
|
||||
equals?: IEqualsComparer<T>;
|
||||
};
|
||||
readonly configName: string;
|
||||
|
||||
migrations?: Migrations<Record<string, unknown>>;
|
||||
readonly migrations?: Migrations;
|
||||
|
||||
/**
|
||||
* fromStore is called internally when a child class syncs with the file
|
||||
@ -91,7 +90,7 @@ const createPersistentStorageInjectable = getInjectable({
|
||||
const config = getConfigurationFileModel({
|
||||
projectName: "lens",
|
||||
cwd,
|
||||
migrations: migrations as Migrations<T>,
|
||||
migrations: migrations as Options<T>["migrations"],
|
||||
...params,
|
||||
});
|
||||
|
||||
|
||||
@ -4,19 +4,26 @@
|
||||
*/
|
||||
import type { InjectionToken } from "@ogre-tools/injectable";
|
||||
import { lifecycleEnum, getInjectable } from "@ogre-tools/injectable";
|
||||
import type { Migrations } from "conf/dist/source/types";
|
||||
import loggerInjectable from "../logger.injectable";
|
||||
import { getOrInsert, iter } from "@k8slens/utilities";
|
||||
import { getOrInsert, iter, object } from "@k8slens/utilities";
|
||||
|
||||
export type AllowedSetValue<T> = T extends (...args: any[]) => any
|
||||
? never
|
||||
: T extends undefined | symbol
|
||||
? never
|
||||
: T;
|
||||
|
||||
export interface MigrationStore {
|
||||
readonly path: string;
|
||||
get(key: string): unknown;
|
||||
delete(key: string): void;
|
||||
has(key: string): boolean;
|
||||
clear(): void;
|
||||
set(key: string, value: number | string | boolean | unknown[]): void;
|
||||
set<Key extends string>(key: string, value: Record<Key, unknown>): void;
|
||||
set<T>(key: string, value: AllowedSetValue<T>): void;
|
||||
}
|
||||
|
||||
export type Migrations = Partial<Record<string, (store: MigrationStore) => void>>;
|
||||
|
||||
export interface MigrationDeclaration {
|
||||
version: string;
|
||||
run(store: MigrationStore): void;
|
||||
@ -24,7 +31,7 @@ export interface MigrationDeclaration {
|
||||
|
||||
const persistentStorageMigrationsInjectable = getInjectable({
|
||||
id: "persistent-storage-migrations",
|
||||
instantiate: (di, token): Migrations<Record<string, unknown>> => {
|
||||
instantiate: (di, token) => {
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const declarations = di.injectMany(token);
|
||||
const migrations = new Map<string, MigrationDeclaration["run"][]>();
|
||||
@ -33,18 +40,15 @@ const persistentStorageMigrationsInjectable = getInjectable({
|
||||
getOrInsert(migrations, decl.version, []).push(decl.run);
|
||||
}
|
||||
|
||||
return Object.fromEntries(
|
||||
iter.map(
|
||||
migrations,
|
||||
([v, fns]) => [v, (store) => {
|
||||
logger.info(`Running ${v} migration for ${store.path}`);
|
||||
return iter.chain(migrations.entries())
|
||||
.map(([v, fns]) => [v, (store: MigrationStore) => {
|
||||
logger.info(`Running ${v} migration for ${store.path}`);
|
||||
|
||||
for (const fn of fns) {
|
||||
fn(store);
|
||||
}
|
||||
}],
|
||||
),
|
||||
);
|
||||
for (const fn of fns) {
|
||||
fn(store);
|
||||
}
|
||||
}] as const)
|
||||
.collect(object.fromEntries);
|
||||
},
|
||||
lifecycle: lifecycleEnum.keyedSingleton({
|
||||
getInstanceKey: (di, token: InjectionToken<MigrationDeclaration, void>) => token.id,
|
||||
|
||||
@ -8,14 +8,15 @@ import type { LensExtension } from "./lens-extension";
|
||||
import type { StaticThis } from "../common/utils/singleton";
|
||||
import { getOrInsertWith } from "@k8slens/utilities";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "./as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import type { Migrations } from "conf/dist/source/types";
|
||||
import type { PersistentStorage, PersistentStorageParams } from "../common/persistent-storage/create.injectable";
|
||||
import createPersistentStorageInjectable from "../common/persistent-storage/create.injectable";
|
||||
import directoryForUserDataInjectable from "../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import assert from "assert";
|
||||
import type { Options } from "conf";
|
||||
import type { Migrations } from "../common/persistent-storage/migrations.injectable";
|
||||
|
||||
export interface ExtensionStoreParams<T extends object> extends Omit<PersistentStorageParams<T>, "migrations" | "cwd" | "fromStore" | "toJSON"> {
|
||||
migrations?: Migrations<T>;
|
||||
migrations?: Options<T>["migrations"];
|
||||
cwd?: string;
|
||||
}
|
||||
|
||||
@ -76,7 +77,7 @@ export abstract class BaseExtensionStore<T extends object> {
|
||||
...params,
|
||||
cwd: this.cwd(),
|
||||
projectVersion,
|
||||
migrations: migrations as Migrations<Record<string, unknown>>,
|
||||
migrations: migrations as Migrations,
|
||||
fromStore: (data) => this.fromStore(data),
|
||||
toJSON: () => this.toJSON(),
|
||||
});
|
||||
|
||||
@ -26,8 +26,6 @@ const clustersPersistentStorageInjectable = getInjectable({
|
||||
const readClusterConfigSync = di.inject(readClusterConfigSyncInjectable);
|
||||
const clustersState = di.inject(clustersStateInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const storeMigrationVersion = di.inject(storeMigrationVersionInjectable);
|
||||
const migrations = di.inject(persistentStorageMigrationsInjectable, clusterStoreMigrationInjectionToken);
|
||||
|
||||
return createPersistentStorage<ClusterStoreModel>({
|
||||
configName: "lens-cluster-store",
|
||||
@ -35,8 +33,8 @@ const clustersPersistentStorageInjectable = getInjectable({
|
||||
syncOptions: {
|
||||
equals: comparer.structural,
|
||||
},
|
||||
projectVersion: storeMigrationVersion,
|
||||
migrations,
|
||||
projectVersion: di.inject(storeMigrationVersionInjectable),
|
||||
migrations: di.inject(persistentStorageMigrationsInjectable, clusterStoreMigrationInjectionToken),
|
||||
fromStore: action(({ clusters = [] }) => {
|
||||
const currentClusters = new Map(clustersState);
|
||||
const newClusters = new Map<ClusterId, Cluster>();
|
||||
|
||||
@ -11,6 +11,8 @@ interface Iterator<T> extends Iterable<T> {
|
||||
find(fn: (val: T) => unknown): T | undefined;
|
||||
collect<U>(fn: (values: Iterable<T>) => U): U;
|
||||
toArray(): T[];
|
||||
toMap(): T extends [infer K, infer V] ? Map<K, V> : never;
|
||||
toSet(): Set<T>;
|
||||
map<U>(fn: (val: T) => U): Iterator<U>;
|
||||
flatMap<U>(fn: (val: T) => U[]): Iterator<U>;
|
||||
concat(src2: IterableIterator<T>): Iterator<T>;
|
||||
@ -28,6 +30,8 @@ function chain<T>(src: IterableIterator<T>): Iterator<T> {
|
||||
join: (sep) => join(src, sep),
|
||||
collect: (fn) => fn(src),
|
||||
toArray: () => [...src],
|
||||
toMap: () => new Map(src as IterableIterator<[any, any]>) as any,
|
||||
toSet: () => new Set(src),
|
||||
concat: (src2) => chain(concat(src, src2)),
|
||||
take: (count) => chain(take(src, count)),
|
||||
[Symbol.iterator]: () => src,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user