Skip to content

Workflow ​

A workflow has a versioned Workflow and one registered WorkflowHandler. The definition owns identity and payload boundaries; the handler owns deterministic orchestration. JSON documents compile to handlers and do not form a second engine.

Define in Dart ​

dart
final orderDefinition = Workflow<
  OrderInput,
  OrderResult,
  OrderFailure
>(
  code: 'order-approval',
  version: 1,
  input: orderInputSchema,
  output: orderResultSchema,
  failure: orderFailureSchema,
);

final orderHandler = orderDefinition.implement(
  fingerprint: deploymentFingerprint,
  execute: (workflow, input) async {
    final order = await workflow.perform(
      loadOrder,
      input.orderId,
      id: 'load-order',
    );
    final decision = await workflow.request(
      approvalWork,
      order,
      id: 'approve-order',
      title: 'Approve order',
      audience: const Audience(
        roleIds: ['order-approver'],
      ),
    );
    if (!decision.approved) return OrderResult.rejected();
    return OrderResult.approved(order.id);
  },
);

code + version is immutable. fingerprint prevents two deployments from silently using different code for the same identity.

Dart conditions, loops, functions, and typed values are allowed. Direct I/O, clocks, randomness, and Future.wait are not. Use workflow.parallel so every branch has a stable replay identity.

Define in JSON ​

The JSON format is small. References use name:vN. Bindings are data, not executable expressions.

json
{
  "code": "order-approval",
  "formatVersion": 2,
  "version": 2,
  "fingerprint": "order-approval-v1-build-42",
  "start": "load-order",
  "steps": [
    {
      "id": "load-order",
      "type": "operation",
      "operation": "orders.load:v1",
      "inputBinding": "$.input.orderId",
      "next": "approve"
    },
    {
      "id": "approve",
      "type": "work",
      "work": "orders.approve:v1",
      "title": "Approve order",
      "audience": {"roleIds": ["order-approver"]},
      "outcomes": {"approved": "approved", "rejected": "rejected"}
    },
    {
      "id": "approved",
      "type": "end",
      "outputBinding": {"status": "approved"}
    },
    {
      "id": "rejected",
      "type": "end",
      "outputBinding": {"status": "rejected"}
    }
  ]
}
dart
final handler = WorkflowDocument.compileJson(jsonMap);

Compilation is one-way. The compiler rejects unknown fields, duplicate IDs, dangling transitions, and invalid retries before registration.

Construction API ​

APICreates
Workflow.refTyped reference to another workflow
WorkflowTyped workflow definition with three schemas
OperationTyped automated-execution definition with three schemas
WorkVersioned assigned-work request and response contract
EventVersioned external-event contract
WorkflowDocument.compileJsonCompile a JSON document to a WorkflowHandler

Pass an optional validated manifest to definition.implement(...) when the inspector needs a complete pre-run map. Dart remains the executable source.

See Also ​