Input validation
Validate and type workflow input with any Standard Schema library.
inputSchema accepts any Standard Schema validator, including Zod, Valibot, and ArkType. startWorkflow validates the input before creating the run, and the handler's input is typed from the schema.
Zod:
import { workflow } from 'pg-workflows'
import { z } from 'zod'
const onboarding = workflow(
'user-onboarding',
async ({ step, input }) => {
// input: { email: string; name: string }
await step.run('greet', async () => `Welcome, ${input.name}`)
},
{ inputSchema: z.object({ email: z.email(), name: z.string() }) },
)Valibot:
import { workflow } from 'pg-workflows'
import * as v from 'valibot'
const onboarding = workflow(
'user-onboarding',
async ({ step, input }) => {
// input: { email: string; name: string }
await step.run('greet', async () => `Welcome, ${input.name}`)
},
{ inputSchema: v.object({ email: v.pipe(v.string(), v.email()), name: v.string() }) },
)No schema. input is unknown and isn't validated, so narrow it yourself:
const refund = workflow('refund', async ({ step, input }) => {
const { orderId } = input as { orderId: string }
await step.run('refund-order', async () => ({ refunded: orderId }))
})