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
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.
{
"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"}
}
]
}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
| API | Creates |
|---|---|
Workflow.ref | Typed reference to another workflow |
Workflow | Typed workflow definition with three schemas |
Operation | Typed automated-execution definition with three schemas |
Work | Versioned assigned-work request and response contract |
Event | Versioned external-event contract |
WorkflowDocument.compileJson | Compile 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.