feat(workflows-sdk): Allow primitive values to be passed as well as WorkflowDataProperties (#5953)

* feat(workflows-sdk): Allow primitive values to be passed as well as WorkflowDataProperties

* feat(workflows-sdk): improve playground tests

* Create nine-shrimps-reply.md
This commit is contained in:
Adrien de Peretti authored and GitHub committed 2023-12-22 07:39:28 +01:00
1 parent bfd10dadaf
commit a0dd18c12a
3 files changed
+15 -9

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/workflows-sdk": patch
---
feat(workflows-sdk): Allow primitive values to be passed as well as WorkflowDataProperties
@@ -1,14 +1,15 @@
import { createStep, createWorkflow, StepResponse } from "./composer" import { createStep, createWorkflow, StepResponse } from "./composer"
const step1 = createStep("step1", async (input: {}, context) => { const step1 = createStep("step1", async (input: {}, context) => {
console.log("step1", input) // Here the input will be `{}` and the createWorkflow does not have to provide an input
return new StepResponse({ step1: "step1" }) return new StepResponse({ step1: "step1" })
}) })
const step2 = createStep("step2", async (input: string, context) => { const step2 = createStep(
console.log("step2", input) // Here the input will be the string value `step1` "step2",
return new StepResponse({ step2: "step2" }) async (input: { test: string; test2: string }, context) => {
}) return new StepResponse({ step2: input })
}
)
const step3 = createStep("step3", async () => { const step3 = createStep("step3", async () => {
return new StepResponse({ step3: "step3" }) return new StepResponse({ step3: "step3" })
@@ -17,11 +18,11 @@ const step3 = createStep("step3", async () => {
const workflow = createWorkflow("workflow", function () { const workflow = createWorkflow("workflow", function () {
const step1Res = step1() const step1Res = step1()
step3() step3()
return step2(step1Res.step1) return step2({ test: "test", test2: step1Res.step1 })
}) })
workflow() workflow()
.run({}) .run({})
.then((res) => { .then((res) => {
console.log(res.result) // result: { step2: "step2" } console.log(res.result) // result: { step2: { test: "test", test2: "step1" } }
}) })
@@ -29,8 +29,8 @@ export type StepFunction<TInput, TOutput = unknown> = (keyof TInput extends []
{ {
( (
input: TInput extends object input: TInput extends object
? { [K in keyof TInput]: WorkflowData<TInput[K]> } ? { [K in keyof TInput]: WorkflowData<TInput[K]> | TInput[K] }
: WorkflowData<TInput> : WorkflowData<TInput> | TInput
): WorkflowData<{ ): WorkflowData<{
[K in keyof TOutput]: TOutput[K] [K in keyof TOutput]: TOutput[K]
}> }>