Command

A command is a single function, which will be called (invoked) by someone with the expectation to get a result back.
Add a command to an existing service with purista add command.
Commands can access service resources (for example database clients/connections) via context.resources. Resources are provided when creating the service instance with serviceBuilder.getInstance(eventBridge, { resources: ... }).
Command lifecycle
- optional input transform
- payload/parameter validation
- before guards
- command function execution
- output validation
- after guards
- optional output transform
What to read next
When to use
- You need request/response behavior.
- A caller expects success/error result semantics.
- You want strict validation on input/output contracts.
Common pitfalls
- mixing long-running asynchronous workflows into one command
- overusing broad payload schemas instead of explicit contracts
- forgetting to define output schema, then losing type guarantees
Checklist
- payload, parameter and output schemas are defined
- guards are used for auth/authz concerns
- command is exposed (or intentionally internal only)
- unit tests cover success and failure paths
