Skip to content
Prose v0.3.2

createFlow

function createFlow<TInput, TDeps extends BaseFlowDependencies = never>(
name: string
): FlowBuilder<TInput, TDeps, {}, never>

Type: string

A human-readable name for the flow. Used in error messages, observer hooks, and ctx.meta.flowName.

The shape of the input object passed to .execute(). This is available as ctx.input in every step handler.

const flow = createFlow<{ orderId: string; userId: string }>('process-order');

The shape of the dependencies object passed as the second argument to .execute(). Must extend BaseFlowDependencies, which optionally includes db?: DatabaseClient and eventPublisher?: FlowEventPublisher. Provide them when your flow uses .transaction() or .event() steps.

Defaults to never — when you omit TDeps, TypeScript won’t require any specific dependencies. Once you use .transaction() or .event() steps, you’ll need to provide a concrete type that satisfies the contract.

type Deps = {
db: DatabaseClient;
eventPublisher: FlowEventPublisher;
};
const flow = createFlow<{ orderId: string }, Deps>('process-order');

A FlowBuilder instance with the following initial state:

  • State type: {} (empty)
  • Break outputs: never (no early exits defined yet)

Chain builder methods (.step(), .validate(), etc.) to define the flow, then call .build().

import { createFlow } from '@celom/prose';
const flow = createFlow<{ email: string }>('onboard-user')
.step('create', async (ctx) => {
const user = await db.createUser(ctx.input.email);
return { user };
})
.build();
const result = await flow.execute(
{ email: 'alice@example.com' },
{ db }
);