feat: add in the action meta metadata

This commit is contained in:
BluJ
2023-05-09 14:03:07 -06:00
parent 715ddff896
commit bc13fe06fe
5 changed files with 38 additions and 11 deletions

View File

@@ -12,13 +12,13 @@ export class CreatedAction<
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
> {
private constructor(
public readonly myMetaData: ActionMetaData,
public readonly myMetaData: Omit<ActionMetaData, "input">,
readonly fn: (options: {
effects: Effects
utils: Utils<Store>
input: Type
}) => Promise<ActionResult>,
readonly input: Config<Type, Store> | Config<Type, never>,
readonly input: Config<Type, Store>,
) {}
public validator = this.input.validator
@@ -40,7 +40,11 @@ export class CreatedAction<
}) => Promise<ActionResult>,
) {
const { input, ...rest } = metaData
return new CreatedAction<Store, ConfigType, Type>(rest, fn, input)
return new CreatedAction<Store, ConfigType, Type>(
rest,
fn,
input as Config<Type, Store>,
)
}
exportedAction: ExportedAction = ({ effects, input }) => {
@@ -59,6 +63,16 @@ export class CreatedAction<
})
}
async actionMetaData(options: {
effects: Effects
utils: Utils<Store>
}): Promise<ActionMetaData> {
return {
...this.myMetaData,
input: await this.input.build(options),
}
}
async getConfig({ effects }: { effects: Effects }) {
return this.input.build({
effects,