mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-01 04:53:40 +00:00
* add error status * update types * ṗ̶̰̙̓͒̈́ͅü̵̢̙̫̣ŗ̷̪̺̺͛g̴̲͉͎̬̒̇e̵̪̎̅͌ ̶̡̜̘͐͛t̶͎͍̣̿̍̐h̴͕̩͗̈́̎̑e̵͚͒̂͝ ̸̛͙̦͈͝v̶̱͙̬̽̔ọ̶̧̡̒̓i̸̬̲͍̋̈́d̴͉̀ * fix some extra voids * add `package.rebuild` * introduce error status and pkg rebuild and fix mocks * minor fixes * fix build --------- Co-authored-by: Matt Hill <mattnine@protonmail.com>
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import * as T from "../types"
|
|
import { once } from "../util"
|
|
import { Dependency } from "./Dependency"
|
|
|
|
type DependencyType<Manifest extends T.Manifest> = {
|
|
[K in keyof {
|
|
[K in keyof Manifest["dependencies"]]: Manifest["dependencies"][K]["optional"] extends false
|
|
? K
|
|
: never
|
|
}]: Dependency
|
|
} & {
|
|
[K in keyof {
|
|
[K in keyof Manifest["dependencies"]]: Manifest["dependencies"][K]["optional"] extends true
|
|
? K
|
|
: never
|
|
}]?: Dependency
|
|
}
|
|
|
|
export function setupDependencies<Manifest extends T.Manifest>(
|
|
fn: (options: { effects: T.Effects }) => Promise<DependencyType<Manifest>>,
|
|
): (options: { effects: T.Effects }) => Promise<null> {
|
|
const cell = { updater: async (_: { effects: T.Effects }) => null }
|
|
cell.updater = async (options: { effects: T.Effects }) => {
|
|
options.effects = {
|
|
...options.effects,
|
|
constRetry: once(() => {
|
|
cell.updater(options)
|
|
}),
|
|
}
|
|
const dependencyType = await fn(options)
|
|
return await options.effects.setDependencies({
|
|
dependencies: Object.entries(dependencyType).map(
|
|
([
|
|
id,
|
|
{
|
|
data: { versionRange, ...x },
|
|
},
|
|
]) => ({
|
|
id,
|
|
...x,
|
|
...(x.type === "running"
|
|
? {
|
|
kind: "running",
|
|
healthChecks: x.healthChecks,
|
|
}
|
|
: {
|
|
kind: "exists",
|
|
}),
|
|
versionRange: versionRange.toString(),
|
|
}),
|
|
),
|
|
})
|
|
}
|
|
return cell.updater
|
|
}
|