# commandServiceBuilder

Takes a list of actions and a repository and returns an object where action names map to executable commands.&#x20;

Each command accepts an id and a payload.  When invoked, a command loads the current state of the entity from the repo and passes it, and the payload, to the action. The action will perform its validation and if successful, generate one or more events. The command forwards those events to the repository to be appended to the entity.

## Methods

### build

`build({ actions, repository })`&#x20;

Turns actions into commands that can be executed on real objects.

#### Parameters

| attribute    | type     | description                          |
| ------------ | -------- | ------------------------------------ |
| `actions`    | `object` | [Domain](/domain.md#actions) actions |
| `repository` | `object` | generated by the `repositoryBuilder` |

#### Returns

`commands` - where keys are actions names and values are functions which accept an `id` and `payload`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.serverless-cqrs.com/components/write-model/commandservicebuilder.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
