Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(workflows-sdk): Allow a step to not define an expected input #5775

Merged
merged 6 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hip-turtles-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/workflows-sdk": patch
---

feat(workflows-sdk): Allow a step to not define an expected input
4 changes: 3 additions & 1 deletion packages/workflows-sdk/src/utils/composer/create-step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ function applyStep<
context: transactionContext.context,
}

const argInput = await resolveValue(input, transactionContext)
const argInput = input
? await resolveValue(input, transactionContext)
: undefined
const stepResponse: StepResponse<any, any> = await invokeFn.apply(
this,
[argInput, executionContext]
Expand Down
22 changes: 17 additions & 5 deletions packages/workflows-sdk/src/utils/composer/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,25 @@ export type StepFunctionResult<TOutput extends unknown | unknown[] = unknown> =
* @typeParam TInput - The type of the input of the step.
* @typeParam TOutput - The type of the output of the step.
*/
export type StepFunction<TInput extends object = object, TOutput = unknown> = {
(input: { [K in keyof TInput]: WorkflowData<TInput[K]> }): WorkflowData<{
export type StepFunction<
TInput extends object = object,
TOutput = unknown
> = (TInput extends unknown
? // Function that doesn't expect any input
{
(): WorkflowData<{
[K in keyof TOutput]: TOutput[K]
}>
}
: // function that expects an input object
{
(input: { [K in keyof TInput]: WorkflowData<TInput[K]> }): WorkflowData<{
[K in keyof TOutput]: TOutput[K]
}>
}) &
WorkflowDataProperties<{
[K in keyof TOutput]: TOutput[K]
}>
} & WorkflowDataProperties<{
[K in keyof TOutput]: TOutput[K]
}>

export type WorkflowDataProperties<T = unknown> = {
__type: Symbol
Expand Down