Type Alias: ProcessDefinitionConfig<T> {#type-alias-processdefinitionconfigt}
ProcessDefinitionConfig<
T> =object
Configuration object for Engine.process. Replaces positional arguments with a single named config, making registrations easier to read.
Example {#example}
engine.process({
name: 'send-welcome',
on: 'user:signup',
schema: z.object({ email: z.string(), name: z.string() }),
retry: { maxRetries: 3, delay: 1000 },
run: async (ctx) => {
await ctx.effect({
key: 'welcome-email',
run: () => sendEmail(ctx.payload.email, `Welcome, ${ctx.payload.name}!`),
})
return ctx.ok()
},
})
Type Parameters {#type-parameters}
T {#t}
T = unknown
Properties {#properties}
emits? {#emits}
optionalemits:string[]
Event names this process may emit via triggerEvent in the handler result.
Used to build the static event flow graph returned by Engine.getGraph.
Example {#emits-example}
engine.process({
name: 'validate',
on: 'order:new',
emits: ['order:validated', 'order:rejected'],
run: async (ctx) => {
const valid = await validate(ctx.payload)
return ctx.ok(ctx.payload, { emit: valid ? 'order:validated' : 'order:rejected' })
},
})
name {#name}
name:
string
Unique name identifying this process.
on {#on}
on:
string
The event name this process listens for.
retry? {#retry}
optionalretry:RetryPolicy
Optional retry policy for automatic retries on failure.
run() {#run}
run: (
ctx) =>Promise<HandlerResult> |HandlerResult
The handler function executed when the event fires.
Parameters {#run-parameters}
ctx {#run-ctx}
Returns {#run-returns}
Promise<HandlerResult> | HandlerResult
schema? {#schema}
optionalschema:Schema<T>
Optional schema to validate event payloads before execution.
singleton? {#singleton}
optionalsingleton:boolean
When true, only one run of this process may be active (idle or running) at a time. Additional events are silently dropped.
Default Value {#singleton-default-value}
false
version? {#version}
optionalversion:string
Optional version string for handler versioning and migration.