mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Simplify convertToWithIdWith
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
1fc31d39ca
commit
83950f46ce
@ -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 { DiContainerForInjection, Injectable, InjectionInstanceWithMeta } from "@ogre-tools/injectable";
|
import type { DiContainerForInjection, InjectionInstanceWithMeta } from "@ogre-tools/injectable";
|
||||||
import { getOrInsertSetFor, isDefined } from "../utils";
|
import { getOrInsertSetFor, isDefined } from "../utils";
|
||||||
import * as uuid from "uuid";
|
import * as uuid from "uuid";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
@ -75,33 +75,20 @@ export function verifyRunnablesAreDAG<Param>(tokenId: string, runnables: (Runnab
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ConvertToWithId {
|
||||||
|
<Param>(src: InjectionInstanceWithMeta<Runnable<Param>>): RunnableWithId<Param>;
|
||||||
|
<Param>(src: InjectionInstanceWithMeta<RunnableSync<Param>>): RunnableSyncWithId<Param>;
|
||||||
|
}
|
||||||
|
|
||||||
export const convertToWithIdWith = (di: DiContainerForInjection) => {
|
export const convertToWithIdWith = (di: DiContainerForInjection) => {
|
||||||
const convertToWithIdPlain = <Param>(injectable: Injectable<Runnable<Param>, Runnable<Param>, void>): RunnableWithId<Param> => {
|
const convert = <Param>(meta: { id: string }, instance: Runnable<Param>): RunnableWithId<Param> => ({
|
||||||
const instance = di.inject(injectable);
|
id: meta.id,
|
||||||
|
run: instance.run,
|
||||||
|
runAfter: [instance.runAfter]
|
||||||
|
.flat()
|
||||||
|
.filter(isDefined)
|
||||||
|
.map((injectable) => convert(injectable, di.inject(injectable))),
|
||||||
|
});
|
||||||
|
|
||||||
return ({
|
return ((src) => convert(src.meta, src.instance)) as ConvertToWithId;
|
||||||
id: injectable.id,
|
|
||||||
run: instance.run,
|
|
||||||
runAfter: [instance.runAfter]
|
|
||||||
.flat()
|
|
||||||
.filter(isDefined)
|
|
||||||
.map(convertToWithIdPlain),
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function convertToWithId<Param>(src: InjectionInstanceWithMeta<Runnable<Param>>): RunnableWithId<Param>;
|
|
||||||
function convertToWithId<Param>(src: InjectionInstanceWithMeta<RunnableSync<Param>>): RunnableSyncWithId<Param>;
|
|
||||||
|
|
||||||
function convertToWithId<Param>(src: InjectionInstanceWithMeta<Runnable<Param>> | InjectionInstanceWithMeta<RunnableSync<Param>>): RunnableWithId<Param> | RunnableSyncWithId<Param> {
|
|
||||||
return ({
|
|
||||||
id: src.meta.id,
|
|
||||||
run: src.instance.run,
|
|
||||||
runAfter: [src.instance.runAfter]
|
|
||||||
.flat()
|
|
||||||
.filter(isDefined)
|
|
||||||
.map(convertToWithIdPlain),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return convertToWithId;
|
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user