diff --git a/lib/StartSDK.ts b/lib/StartSDK.ts index e2427bf..68935a5 100644 --- a/lib/StartSDK.ts +++ b/lib/StartSDK.ts @@ -12,7 +12,7 @@ import { ValueSpecText, } from "./config/configTypes" import { Variants } from "./config/builder/variants" -import { createAction } from "./actions/createAction" +import { CreatedAction, createAction } from "./actions/createAction" import { ActionMetaData, Effects, @@ -200,7 +200,8 @@ export class StartSDK { }) => Promise }) => Migration.of(options), }, - setupActions, + setupActions: (...createdActions: CreatedAction[]) => + setupActions(...createdActions), setupAutoConfig: < Input, NestedConfigs extends { diff --git a/lib/actions/createAction.ts b/lib/actions/createAction.ts index a0cf09b..ff4ba1e 100644 --- a/lib/actions/createAction.ts +++ b/lib/actions/createAction.ts @@ -12,13 +12,13 @@ export class CreatedAction< Type extends Record = ExtractConfigType, > { private constructor( - public readonly myMetaData: ActionMetaData, + public readonly myMetaData: Omit, readonly fn: (options: { effects: Effects utils: Utils input: Type }) => Promise, - readonly input: Config | Config, + readonly input: Config, ) {} public validator = this.input.validator @@ -40,7 +40,11 @@ export class CreatedAction< }) => Promise, ) { const { input, ...rest } = metaData - return new CreatedAction(rest, fn, input) + return new CreatedAction( + rest, + fn, + input as Config, + ) } exportedAction: ExportedAction = ({ effects, input }) => { @@ -59,6 +63,16 @@ export class CreatedAction< }) } + async actionMetaData(options: { + effects: Effects + utils: Utils + }): Promise { + return { + ...this.myMetaData, + input: await this.input.build(options), + } + } + async getConfig({ effects }: { effects: Effects }) { return this.input.build({ effects, diff --git a/lib/actions/setupActions.ts b/lib/actions/setupActions.ts index 5efc844..a116e6b 100644 --- a/lib/actions/setupActions.ts +++ b/lib/actions/setupActions.ts @@ -1,9 +1,11 @@ -import { Effects, ExpectedExports, ExportedAction } from "../types" -import { ActionMetaData } from "../types" +import { Effects, ExpectedExports } from "../types" +import { createUtils } from "../util" import { once } from "../util/once" import { CreatedAction } from "./createAction" -export function setupActions(...createdActions: CreatedAction[]) { +export function setupActions( + ...createdActions: CreatedAction[] +) { const myActions = once(() => { const actions: Record> = {} for (const action of createdActions) { @@ -15,8 +17,14 @@ export function setupActions(...createdActions: CreatedAction[]) { get actions() { return myActions() }, - get actionsMetadata() { - return createdActions.map((x) => x.myMetaData) + async actionMetaData({ effects }: { effects: Effects }) { + const utils = createUtils(effects) + return Promise.all( + createdActions.map((x) => x.actionMetaData({ effects, utils })), + ) }, + } satisfies { + actions: ExpectedExports.actions + actionMetaData: ExpectedExports.actionMetaData } } diff --git a/lib/manifest/ManifestTypes.ts b/lib/manifest/ManifestTypes.ts index f5da303..80b91ad 100644 --- a/lib/manifest/ManifestTypes.ts +++ b/lib/manifest/ManifestTypes.ts @@ -63,7 +63,6 @@ export interface SDKManifest { containers: Record /** This denotes any data, asset, or pointer volumes that should be connected when the "docker run" command is invoked */ volumes: Record - actions: Array alerts: { install: string | null update: string | null diff --git a/lib/types.ts b/lib/types.ts index 900820e..d31f42a 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -45,6 +45,10 @@ export namespace ExpectedExports { } } + export type actionMetaData = (options: { + effects: Effects + }) => Promise> + /** * This is the entrypoint for the main container. Used to start up something like the service that the * package represents, like running a bitcoind in a bitcoind-wrapper. @@ -154,6 +158,7 @@ export type ActionMetaData = { name: string description: string id: string + input: InputSpec allowedStatuses: "only-running" | "only-stopped" | "any" /** * So the ordering of the actions is by alphabetical order of the group, then followed by the alphabetical of the actions