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
2023-12-22 07:39:28 +01:00
committed by GitHub
parent bfd10dadaf
commit a0dd18c12a
3 changed files with 15 additions and 9 deletions

View File

@@ -1,14 +1,15 @@
import { createStep, createWorkflow, StepResponse } from "./composer"
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" })
})
const step2 = createStep("step2", async (input: string, context) => {
console.log("step2", input) // Here the input will be the string value `step1`
return new StepResponse({ step2: "step2" })
})
const step2 = createStep(
"step2",
async (input: { test: string; test2: string }, context) => {
return new StepResponse({ step2: input })
}
)
const step3 = createStep("step3", async () => {
return new StepResponse({ step3: "step3" })
@@ -17,11 +18,11 @@ const step3 = createStep("step3", async () => {
const workflow = createWorkflow("workflow", function () {
const step1Res = step1()
step3()
return step2(step1Res.step1)
return step2({ test: "test", test2: step1Res.step1 })
})
workflow()
.run({})
.then((res) => {
console.log(res.result) // result: { step2: "step2" }
console.log(res.result) // result: { step2: { test: "test", test2: "step1" } }
})

View File

@@ -29,8 +29,8 @@ export type StepFunction<TInput, TOutput = unknown> = (keyof TInput extends []
{
(
input: TInput extends object
? { [K in keyof TInput]: WorkflowData<TInput[K]> }
: WorkflowData<TInput>
? { [K in keyof TInput]: WorkflowData<TInput[K]> | TInput[K] }
: WorkflowData<TInput> | TInput
): WorkflowData<{
[K in keyof TOutput]: TOutput[K]
}>