mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +00:00
feat: Add in the setupExports
This commit is contained in:
13
lib/inits/setupExports.ts
Normal file
13
lib/inits/setupExports.ts
Normal 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
|
||||||
@@ -2,6 +2,7 @@ import { SetInterfaces } from "../interfaces/setupInterfaces"
|
|||||||
import { ExpectedExports } from "../types"
|
import { ExpectedExports } from "../types"
|
||||||
import { createUtils } from "../util"
|
import { createUtils } from "../util"
|
||||||
import { Migrations } from "./migrations/setupMigrations"
|
import { Migrations } from "./migrations/setupMigrations"
|
||||||
|
import { SetupExports } from "./setupExports"
|
||||||
import { Install } from "./setupInstall"
|
import { Install } from "./setupInstall"
|
||||||
import { Uninstall } from "./setupUninstall"
|
import { Uninstall } from "./setupUninstall"
|
||||||
|
|
||||||
@@ -10,19 +11,27 @@ export function setupInit<Store, Vault>(
|
|||||||
install: Install<Store, Vault>,
|
install: Install<Store, Vault>,
|
||||||
uninstall: Uninstall<Store, Vault>,
|
uninstall: Uninstall<Store, Vault>,
|
||||||
setInterfaces: SetInterfaces<Store, Vault, any, any>,
|
setInterfaces: SetInterfaces<Store, Vault, any, any>,
|
||||||
|
setupExports: SetupExports<Store>,
|
||||||
): {
|
): {
|
||||||
init: ExpectedExports.init
|
init: ExpectedExports.init
|
||||||
uninit: ExpectedExports.uninit
|
uninit: ExpectedExports.uninit
|
||||||
} {
|
} {
|
||||||
return {
|
return {
|
||||||
init: async (opts) => {
|
init: async (opts) => {
|
||||||
|
const utils = createUtils<Store>(opts.effects)
|
||||||
await migrations.init(opts)
|
await migrations.init(opts)
|
||||||
await install.init(opts)
|
await install.init(opts)
|
||||||
await setInterfaces({
|
await setInterfaces({
|
||||||
...opts,
|
...opts,
|
||||||
input: null,
|
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) => {
|
uninit: async (opts) => {
|
||||||
await migrations.uninit(opts)
|
await migrations.uninit(opts)
|
||||||
|
|||||||
26
lib/types.ts
26
lib/types.ts
@@ -192,15 +192,23 @@ export type NetworkInterface = {
|
|||||||
*/
|
*/
|
||||||
ui?: boolean
|
ui?: boolean
|
||||||
}
|
}
|
||||||
|
// prettier-ignore
|
||||||
export type ExposeServicePaths<Path extends string, Store> = Array<{
|
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/) */
|
/** 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/) */
|
/** 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 */
|
/** This will be the title for the value field that is returned */
|
||||||
title: string
|
title: string
|
||||||
@@ -340,13 +348,11 @@ export type Effects = {
|
|||||||
*/
|
*/
|
||||||
exportNetworkInterface(options: NetworkInterface): Promise<string>
|
exportNetworkInterface(options: NetworkInterface): Promise<string>
|
||||||
|
|
||||||
exposeForDependents<Store = never, Path extends string = never>(
|
exposeForDependents<Store = never>(
|
||||||
options: ExposeServicePaths<Path, Store>,
|
options: ExposeServicePaths<Store>,
|
||||||
): Promise<void>
|
): Promise<void>
|
||||||
|
|
||||||
exposeUi<Store = never, Path extends string = never>(
|
exposeUi<Store = never>(options: ExposeUiPaths<Store>): Promise<void>
|
||||||
options: ExposeUiPaths<Path, Store>,
|
|
||||||
): Promise<void>
|
|
||||||
/**
|
/**
|
||||||
* There are times that we want to see the addresses that where exported
|
* There are times that we want to see the addresses that where exported
|
||||||
* @param options.addressId If we want to filter the address id
|
* @param options.addressId If we want to filter the address id
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import {
|
|||||||
getNetworkInterfaces,
|
getNetworkInterfaces,
|
||||||
} from "./getNetworkInterfaces"
|
} from "./getNetworkInterfaces"
|
||||||
|
|
||||||
export type Utils<Store, Vault, WrapperOverWrite = { const: never }> = {
|
export type Utils<Store, WrapperOverWrite = { const: never }> = {
|
||||||
checkPortListening(
|
checkPortListening(
|
||||||
port: number,
|
port: number,
|
||||||
options: {
|
options: {
|
||||||
|
|||||||
Reference in New Issue
Block a user