Type Alias: ProcessContext<T> {#type-alias-processcontextt}

ProcessContext<T> = object

Ergonomic handler context passed to ProcessDefinitionConfig.run. Wraps HandlerContext with named-parameter effect calls and ok()/fail() helpers that eliminate return-object boilerplate.

Example {#example}

engine.process({
  name: 'charge',
  on: 'order:paid',
  run: async (ctx) => {
    const charge = await ctx.effect({
      key: 'stripe-charge',
      run: () => stripe.charges.create({ amount: ctx.payload.total }),
    })
    return ctx.ok({ chargeId: charge.id })
  },
})

Type Parameters {#type-parameters}

T {#t}

T = unknown

Properties {#properties}

context {#context}

context: Record<string, unknown>

Mutable key-value context shared across the correlation chain. Deep-copied via structuredClone on each handler invocation, direct mutations to nested objects will not persist. Use setContext to persist changes.


correlationId {#correlationid}

correlationId: string

Correlation ID shared across the entire event chain.


effect {#effect}

effect: EffectFn

Execute a durable side effect with named parameters.


event {#event}

event: string

The event name that triggered this handler.


payload {#payload}

payload: T

The event payload (validated by schema if one was registered).


runId {#runid}

runId: string

Unique identifier of the current run.

Methods {#methods}

fail() {#fail}

fail(error, code?): HandlerResult

Return a failure result with an error message and optional error code.

Parameters {#fail-parameters}

error {#fail-error}

string

code? {#fail-code}

ErrorCode

Returns {#fail-returns}

HandlerResult


ok() {#ok}

ok<P>(payload?, opts?): HandlerResult

Return a success result, optionally with a payload and/or a chained event.

Type Parameters {#ok-type-parameters}

P {#ok-p}

P

Parameters {#ok-parameters}

payload? {#ok-payload}

P

opts? {#ok-opts}
emit? {#ok-emit}

string

Returns {#ok-returns}

HandlerResult


setContext() {#setcontext}

setContext(key, value): void

Set a key-value pair in the run’s shared context.

Parameters {#setcontext-parameters}

key {#setcontext-key}

string

value {#setcontext-value}

unknown

Returns {#setcontext-returns}

void