Files
start-sdk/lib/mainFn/index.ts
2023-05-09 15:55:19 -06:00

41 lines
1.1 KiB
TypeScript

import { Effects, ExpectedExports } from "../types"
import { createMainUtils } from "../util"
import { Utils, utils } from "../util/utils"
import { Daemons } from "./Daemons"
import "./exportInterfaces"
import "./LocalBinding"
import "./LocalPort"
import "./NetworkBuilder"
import "./NetworkInterfaceBuilder"
import "./Origin"
import "./TorBinding"
import "./TorHostname"
import "./Daemons"
/**
* Used to ensure that the main function is running with the valid proofs.
* We first do the folowing order of things
* 1. We get the interfaces
* 2. We setup all the commands to setup the system
* 3. We create the health checks
* 4. We setup the daemons init system
* @param fn
* @returns
*/
export const setupMain = <Store, Vault>(
fn: (o: {
effects: Effects
started(onTerm: () => void): null
utils: Utils<Store, Vault, {}>
}) => Promise<Daemons<any>>,
): ExpectedExports.main => {
return async (options) => {
const result = await fn({
...options,
utils: createMainUtils<Store, Vault>(options.effects),
})
await result.build().then((x) => x.wait())
}
}