feat: Add in the setupExports

This commit is contained in:
Blu-J
2023-05-30 17:21:53 -06:00
parent bb35e676d3
commit 613bf74180
4 changed files with 40 additions and 12 deletions

13
lib/inits/setupExports.ts Normal file
View File

@@ -0,0 +1,13 @@
import { Effects, ExposeServicePaths, ExposeUiPaths } from "../types"
import { Utils } from "../util/utils"
export type SetupExports<Store> = (opts: {
effects: Effects
utils: Utils<Store>
}) => {
ui: ExposeUiPaths<Store>
services: ExposeServicePaths<Store>
}
export const setupExports = <Store>(fn: (opts: SetupExports<Store>) => void) =>
fn

View File

@@ -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<Store, Vault>(
install: Install<Store, Vault>,
uninstall: Uninstall<Store, Vault>,
setInterfaces: SetInterfaces<Store, Vault, any, any>,
setupExports: SetupExports<Store>,
): {
init: ExpectedExports.init
uninit: ExpectedExports.uninit
} {
return {
init: async (opts) => {
const utils = createUtils<Store>(opts.effects)
await migrations.init(opts)
await install.init(opts)
await setInterfaces({
...opts,
input: null,
utils: createUtils<Store, Vault>(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)

View File

@@ -192,15 +192,23 @@ export type NetworkInterface = {
*/
ui?: boolean
}
export type ExposeServicePaths<Path extends string, Store> = Array<{
// prettier-ignore
export type ExposeAllServicePaths<Store, PreviousPath extends string = ""> =
Store extends Record<string, unknown> ? {[K in keyof Store & string]: ExposeAllServicePaths<Store[K], `${PreviousPath}/${K & string}`>}[keyof Store & string] :
PreviousPath
// prettier-ignore
export type ExposeAllUiPaths<Store, PreviousPath extends string = ""> =
Store extends Record<string, unknown> ? {[K in keyof Store & string]: ExposeAllUiPaths<Store[K], `${PreviousPath}/${K & string}`>}[keyof Store & string] :
Store extends string ? PreviousPath :
never
export type ExposeServicePaths<Store> = Array<{
/** Sets the value for the wrapper at the path, it will override, using the [JsonPath](https://jsonpath.com/) */
path: Path & EnsureStorePath<Store, Path>
path: ExposeAllServicePaths<Store>
}>
export type ExposeUiPaths<Path extends string, Store> = Array<{
export type ExposeUiPaths<Store> = Array<{
/** Sets the value for the wrapper at the path, it will override, using the [JsonPath](https://jsonpath.com/) */
path: Path & EnsureStorePath<Store, Path>
path: ExposeAllUiPaths<Store>
/** 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<string>
exposeForDependents<Store = never, Path extends string = never>(
options: ExposeServicePaths<Path, Store>,
exposeForDependents<Store = never>(
options: ExposeServicePaths<Store>,
): Promise<void>
exposeUi<Store = never, Path extends string = never>(
options: ExposeUiPaths<Path, Store>,
): Promise<void>
exposeUi<Store = never>(options: ExposeUiPaths<Store>): Promise<void>
/**
* There are times that we want to see the addresses that where exported
* @param options.addressId If we want to filter the address id

View File

@@ -35,7 +35,7 @@ import {
getNetworkInterfaces,
} from "./getNetworkInterfaces"
export type Utils<Store, Vault, WrapperOverWrite = { const: never }> = {
export type Utils<Store, WrapperOverWrite = { const: never }> = {
checkPortListening(
port: number,
options: {