diff --git a/lib/inits/setupExports.ts b/lib/inits/setupExports.ts new file mode 100644 index 0000000..647a1c8 --- /dev/null +++ b/lib/inits/setupExports.ts @@ -0,0 +1,13 @@ +import { Effects, ExposeServicePaths, ExposeUiPaths } from "../types" +import { Utils } from "../util/utils" + +export type SetupExports = (opts: { + effects: Effects + utils: Utils +}) => { + ui: ExposeUiPaths + services: ExposeServicePaths +} + +export const setupExports = (fn: (opts: SetupExports) => void) => + fn diff --git a/lib/inits/setupInit.ts b/lib/inits/setupInit.ts index ec420c6..e3a4b63 100644 --- a/lib/inits/setupInit.ts +++ b/lib/inits/setupInit.ts @@ -2,6 +2,7 @@ import { SetInterfaces } from "../interfaces/setupInterfaces" import { ExpectedExports } from "../types" import { createUtils } from "../util" import { Migrations } from "./migrations/setupMigrations" +import { SetupExports } from "./setupExports" import { Install } from "./setupInstall" import { Uninstall } from "./setupUninstall" @@ -10,19 +11,27 @@ export function setupInit( install: Install, uninstall: Uninstall, setInterfaces: SetInterfaces, + setupExports: SetupExports, ): { init: ExpectedExports.init uninit: ExpectedExports.uninit } { return { init: async (opts) => { + const utils = createUtils(opts.effects) await migrations.init(opts) await install.init(opts) await setInterfaces({ ...opts, input: null, - utils: createUtils(opts.effects), + utils, }) + const { services, ui } = await setupExports({ + ...opts, + utils, + }) + await opts.effects.exposeForDependents(services) + await opts.effects.exposeUi(ui) }, uninit: async (opts) => { await migrations.uninit(opts) diff --git a/lib/types.ts b/lib/types.ts index 0973753..85fdb23 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -192,15 +192,23 @@ export type NetworkInterface = { */ ui?: boolean } - -export type ExposeServicePaths = Array<{ +// prettier-ignore +export type ExposeAllServicePaths = + Store extends Record ? {[K in keyof Store & string]: ExposeAllServicePaths}[keyof Store & string] : + PreviousPath +// prettier-ignore +export type ExposeAllUiPaths = + Store extends Record ? {[K in keyof Store & string]: ExposeAllUiPaths}[keyof Store & string] : + Store extends string ? PreviousPath : + never +export type ExposeServicePaths = Array<{ /** Sets the value for the wrapper at the path, it will override, using the [JsonPath](https://jsonpath.com/) */ - path: Path & EnsureStorePath + path: ExposeAllServicePaths }> -export type ExposeUiPaths = Array<{ +export type ExposeUiPaths = Array<{ /** Sets the value for the wrapper at the path, it will override, using the [JsonPath](https://jsonpath.com/) */ - path: Path & EnsureStorePath + path: ExposeAllUiPaths /** This will be the title for the value field that is returned */ title: string @@ -340,13 +348,11 @@ export type Effects = { */ exportNetworkInterface(options: NetworkInterface): Promise - exposeForDependents( - options: ExposeServicePaths, + exposeForDependents( + options: ExposeServicePaths, ): Promise - exposeUi( - options: ExposeUiPaths, - ): Promise + exposeUi(options: ExposeUiPaths): Promise /** * There are times that we want to see the addresses that where exported * @param options.addressId If we want to filter the address id diff --git a/lib/util/utils.ts b/lib/util/utils.ts index cabaa5c..ce5f403 100644 --- a/lib/util/utils.ts +++ b/lib/util/utils.ts @@ -35,7 +35,7 @@ import { getNetworkInterfaces, } from "./getNetworkInterfaces" -export type Utils = { +export type Utils = { checkPortListening( port: number, options: {