# madbot_cli.operations

*module*

The steps of a deposit in madbot, each with explicit inputs.

Each function takes a `Client` and the identifiers it works on, and returns
what the API answered. None of them reads a deposit file: a platform that
writes Python can chain them in its own tool. `madbot_cli.plan` and
`madbot_cli.apply` chain them from a file.

Functions named ``find_*`` and ``list_*`` only read; the others write.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1-1)

## madbot_cli.operations.BATCH_SIZE

*attribute* · *module attribute*

```python
BATCH_SIZE = 1000
```

Most data the API takes in one batch (``DATALINK_BATCH_MAX_SIZE`` of the instance).

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L26-26)

## madbot_cli.operations.DATA_ACTIVE

*attribute* · *module attribute*

```python
DATA_ACTIVE = 'active'
```

State of a data madbot has read from its source.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L29-29)

## madbot_cli.operations.DATA_FAILED

*attribute* · *module attribute*

```python
DATA_FAILED = 'failed'
```

State of a data madbot failed to read: see its ``enrichment_error``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L33-33)

## madbot_cli.operations.DATA_IN_PROGRESS

*attribute* · *module attribute*

```python
DATA_IN_PROGRESS = 'in progress'
```

State of a data madbot is reading from its source.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L31-31)

## madbot_cli.operations.FOUND_SHOWN

*attribute* · *module attribute*

```python
FOUND_SHOWN = 10
```

The most names a message gives of what a folder holds instead of the name sought.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L652-652)

## madbot_cli.operations.Log

*attribute* · *module attribute*

```python
Log = Callable[[str], None]
```

Called with a message for each change and failure.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L36-36)

## madbot_cli.operations.NODE_ACTIVE

*attribute* · *module attribute*

```python
NODE_ACTIVE = 'active'
```

State of a node in use.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L109-109)

## madbot_cli.operations.NODE_PENDING

*attribute* · *module attribute*

```python
NODE_PENDING = 'pending'
```

State of a node madbot was given no state for: the web application shows it
as a draft and asks how to create it.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L111-111)

## madbot_cli.operations.RATE_LIMITED

*attribute* · *module attribute*

```python
RATE_LIMITED = 'rate_limited'
```

The code of a source that refuses requests for a while.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L579-579)

## madbot_cli.operations.SEARCH_MIN_LENGTH

*attribute* · *module attribute*

```python
SEARCH_MIN_LENGTH = 3
```

The shortest text the API searches for (EXTERNAL_SEARCH_MIN_LENGTH of the instance).

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L533-533)

## madbot_cli.operations.SUBMISSION_BUSY

*attribute* · *module attribute*

```python
SUBMISSION_BUSY = {'generating metadata', 'submission in progress'}
```

States of a submission while madbot works on it in the background.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1203-1203)

## madbot_cli.operations.activate_node

*function*

```python
def activate_node(client: Client, node: Mapping) -> dict
```

Make a node created as a draft (`NODE_PENDING`) a node in use.

Its title, description and icon are sent back as they are: the API
replaces the node with what it is given.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `node` (`mapping`) — The node, as the API gives it.

**Returns**

- (`dict`) — The node.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L226-249)

## madbot_cli.operations.add_submission_data

*function*

```python
def add_submission_data(client: Client, submission_id: str, datalinks: Iterable[Mapping]) -> list[dict]
```

Add data of a node to a submission.

madbot then makes the metadata objects of the submission again, in the
background: wait for it with `wait_submission`.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `submission_id` (`str`) — The submission.
- `datalinks` (`iterable of mapping`) — The datalinks whose data to add, none already in the submission.

**Returns**

- (`list of dict`) — The data added.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1395-1425)

## madbot_cli.operations.alias_of

*function*

```python
def alias_of(name: str) -> str
```

Make the alias of a sample name, as the web application makes it.

**Parameters**

- `name` (`str`) — The sample name.

**Returns**

- (`str`) — The name without its accents, in lower case, with every character other than a letter, a digit or a space removed, then each run of spaces replaced by "-": ``Élevage_1 (A)`` gives ``elevage1-a``. A sample created in the web application is thus found again.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L899-918)

## madbot_cli.operations.apply_samples

*function*

```python
def apply_samples(client: Client, node_id: str, plan: Mapping, log: Log = _silent) -> dict
```

Create the missing samples of a plan and bind their data to them.

A failure is reported and the next sample or data is handled.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `node_id` (`str`) — The node.
- `plan` (`mapping`) — The plan made by `plan_samples`.
- `log` (`callable`) (default: `_silent`) — Called with a message for each change and failure.

**Returns**

- (`dict`) — ``created``, ``linked`` and ``already_linked`` counts, the ``failures``, and for each sample its ``alias``, ``id`` and bound ``files``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1112-1198)

## madbot_cli.operations.bind_sample

*function*

```python
def bind_sample(client: Client, data_id: str, datalink_id: str, sample_id: str) -> bool
```

Bind a data of a node to a sample of that node.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `data_id` (`str`) — The data.
- `datalink_id` (`str`) — Its datalink in the node of the sample.
- `sample_id` (`str`) — The sample.

**Returns**

- (`bool`) — True when the binding is new, False when it was already there.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1084-1109)

## madbot_cli.operations.browse

*function*

```python
def browse(client: Client, connection_id: str, parent: str | None = None) -> list[dict]
```

List what a source holds at one level.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `connection_id` (`str`) — The connection to the source.
- `parent` (`str`) (default: `None`) — The ``id`` (external identifier) of a container; the root of the source when None.

**Returns**

- (`list of dict`) — The objects, each with its ``id``, ``name``, ``type`` and ``has_children``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L453-478)

## madbot_cli.operations.browse_path

*function*

```python
def browse_path(client: Client, connection_id: str, path: Iterable[str]) -> str | None
```

Follow a path of names from the root of a source.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `connection_id` (`str`) — The connection to the source.
- `path` (`iterable of str`) — The names of the containers, from the root.

**Returns**

- (`str or None`) — The external identifier of the last container, None for the root.

**Raises**

- `MadbotError` — When a name is not found, with the names found at that level.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L481-530)

## madbot_cli.operations.close_names

*function*

```python
def close_names(name: str, names: Iterable[str]) -> list[str]
```

Find the names of a folder close to a name, whatever their case.

**Parameters**

- `name` (`str`) — The name sought.
- `names` (`iterable of str`) — The names the folder holds.

**Returns**

- (`list of str`) — At most `FOUND_SHOWN` names: those equal to `name` but for the case first, such as ``README.md`` for ``readme.md``, then the closest.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L656-680)

## madbot_cli.operations.connect

*function*

```python
def connect(client: Client, plugin_id: str, shared_params: Mapping[str, Any], private_params: Mapping[str, Any] | None = None, name: str | None = None) -> dict
```

Connect the workspace to a source or a repository, or give the account its credentials.

The API returns the existing connection when one has the same plugin and
shared parameters, and stores the credentials of the account for it.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `plugin_id` (`str`) — The identifier of the plugin.
- `shared_params` (`mapping`) — The parameters shared by the members, such as the address.
- `private_params` (`mapping`) (default: `None`) — The credentials of the account. A repository may go without.
- `name` (`str`) (default: `None`) — The name of a new connection; computed by the plugin otherwise.

**Returns**

- (`dict`) — The connection.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L373-412)

## madbot_cli.operations.create_node

*function*

```python
def create_node(client: Client, title: str, description: str | None = None, parent: str | None = None) -> dict
```

Create a node in the workspace of the client, at the top or under a node.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `title` (`str`) — The title of the node.
- `description` (`str`) (default: `None`) — Its description.
- `parent` (`str`) (default: `None`) — The node to create it under; at the top of the workspace when None.

**Returns**

- (`dict`) — The node.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L193-223)

## madbot_cli.operations.create_sample

*function*

```python
def create_sample(client: Client, node_id: str, title: str, alias: str) -> dict
```

Create a sample in a node.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `node_id` (`str`) — The node.
- `title` (`str`) — The title of the sample.
- `alias` (`str`) — Its alias, unique in the node.

**Returns**

- (`dict`) — The sample.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1059-1081)

## madbot_cli.operations.create_submission

*function*

```python
def create_submission(client: Client, title: str, connection_id: str, settings: Mapping[str, Any] | None = None) -> dict
```

Create a submission to a repository.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `title` (`str`) — The title of the submission.
- `connection_id` (`str`) — The connection to the repository.
- `settings` (`mapping`) (default: `None`) — The settings the repository asks for, such as a checklist.

**Returns**

- (`dict`) — The submission.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1277-1305)

## madbot_cli.operations.create_workspace

*function*

```python
def create_workspace(client: Client, name: str) -> dict
```

Create a workspace, owned by the account.

**Parameters**

- `client` (`Client`) — The client.
- `name` (`str`) — The name of the workspace.

**Returns**

- (`dict`) — The workspace.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L88-104)

## madbot_cli.operations.current_value

*function*

```python
def current_value(item: Mapping) -> Any
```

Return the value of a metadata item of a submission.

**Parameters**

- `item` (`mapping`) — A metadata item, as ``include_metadata=true`` lists it.

**Returns**

- (`Any`) — Its value, None when it has none.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1450-1465)

## madbot_cli.operations.data_name

*function*

```python
def data_name(datalink: Mapping) -> str
```

Return the name of the data of a datalink.

**Parameters**

- `datalink` (`dict`) — A datalink as the API lists it.

**Returns**

- (`str`) — The name of its data, "" when it has none.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L962-976)

## madbot_cli.operations.error_codes

*function*

```python
def error_codes(error: ApiError) -> set[str]
```

Give the codes of a madbot error answer and of its details.

**Parameters**

- `error` (`ApiError`) — The failed request.

**Returns**

- (`set of str`) — Its ``code`` and the ``code`` of each of its ``details``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L583-599)

## madbot_cli.operations.error_message

*function*

```python
def error_message(error: Any) -> str
```

Return the message of an error the API reports, such as why a data could not be read.

**Parameters**

- `error` (`Any`) — The error: a dict with a ``message``, a text, or None.

**Returns**

- (`str`) — Its message.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L756-772)

## madbot_cli.operations.find_connection

*function*

```python
def find_connection(connections: Iterable[Mapping], plugin_id: str, shared_params: Mapping[str, Any]) -> dict | None
```

Find the connection of a plugin with given shared parameters.

madbot keeps one connection per plugin and shared parameters in a
workspace: this is how a connection is recognised.

**Parameters**

- `connections` (`iterable of dict`) — The connections of the workspace.
- `plugin_id` (`str`) — The identifier of the plugin.
- `shared_params` (`mapping`) — The shared parameters, such as the address of the source.

**Returns**

- (`dict or None`) — The connection, None when there is none.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L340-370)

## madbot_cli.operations.find_in_source

*function*

```python
def find_in_source(client: Client, connection_id: str, path: Iterable[str], match: str = '*') -> list[dict]
```

Resolve a path of names and a pattern into the external identifiers of a source.

The external identifier of a data has a format of its own in each
plugin; a path of names is easier to write. The source is browsed
through the API: nothing is written.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `connection_id` (`str`) — The connection to the source.
- `path` (`iterable of str`) — The names of the containers to open, from the root.
- `match` (`str`) (default: `'*'`) — A shell-style pattern (``*.csv``) the names of the objects found there must match.

**Returns**

- (`list of dict`) — ``external_id`` and ``name`` of each object found, sorted by name.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L717-750)

## madbot_cli.operations.find_node

*function*

```python
def find_node(client: Client, title: str, parent: str | None = None) -> dict | None
```

Find a node by its title, at the top of the workspace or under a node.

A node has no other name than its title: look for it before creating
it, so that a second run creates nothing twice.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `title` (`str`) — The title of the node.
- `parent` (`str`) (default: `None`) — The node to look under; the top of the workspace when None.

**Returns**

- (`dict or None`) — The node, None when there is none of that title.

**Raises**

- `MadbotError` — When several nodes have that title there: madbot cannot tell which
one is meant.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L152-190)

## madbot_cli.operations.find_submission

*function*

```python
def find_submission(client: Client, title: str, connection_id: str | None = None) -> dict | None
```

Find a submission of the workspace by its title.

A submission has no other name than its title: look for it before
creating it, so that a second run creates nothing twice.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `title` (`str`) — The title of the submission.
- `connection_id` (`str`) (default: `None`) — The connection to the repository it must go to.

**Returns**

- (`dict or None`) — The submission, None when the workspace has none of that title.

**Raises**

- `MadbotError` — When several submissions have that title, or the one of that title
goes to another repository than `connection_id`. Two submissions of
the same title are refused even when they go to two repositories:
`connection_id` checks the one found, it does not choose between
them, as ``madbot-cli plan`` does.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1224-1274)

## madbot_cli.operations.find_workspace

*function*

```python
def find_workspace(client: Client, name: str) -> dict | None
```

Find a workspace of the account by its name.

**Parameters**

- `client` (`Client`) — The client.
- `name` (`str`) — The name of the workspace.

**Returns**

- (`dict or None`) — The workspace, None when the account has none of that name.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L66-85)

## madbot_cli.operations.found_by_search

*function*

```python
def found_by_search(client: Client, connection_id: str, name: str, parent: str | None) -> dict | None
```

Find an object a folder does not list, by searching the source.

The object found is the one whose identifier or name is `name`, else
the only result of the search, such as the record a DOI names. Only a
folder that lists nothing is searched, such as the root of Zenodo.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `connection_id` (`str`) — The connection to the source.
- `name` (`str`) — The name, identifier or DOI written in the path.
- `parent` (`str or None`) — The container searched; the whole source when None.

**Returns**

- (`dict or None`) — The object; None when the search finds none or several, or when the source cannot search.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L602-649)

## madbot_cli.operations.found_instead

*function*

```python
def found_instead(name: str, children: list[dict]) -> str
```

Say what a folder holds instead of a name not found, in a few names.

A folder may hold thousands of objects: the message gives those close to
the name sought, else the first ones, and how many there are.

**Parameters**

- `name` (`str`) — The name sought.
- `children` (`list of dict`) — What the folder holds.

**Returns**

- (`str`) — Such as ``Close to it: raw, raw-old (1,204 in all; madbot-cli browse lists them).``

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L683-714)

## madbot_cli.operations.generate_metadata

*function*

```python
def generate_metadata(client: Client, submission_id: str) -> dict
```

Ask madbot to make the metadata of a submission again, and check whether it is ready.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `submission_id` (`str`) — The submission.

**Returns**

- (`dict`) — The submission, generating its metadata.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1570-1588)

## madbot_cli.operations.get_submission

*function*

```python
def get_submission(client: Client, submission_id: str) -> dict
```

Read a submission.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `submission_id` (`str`) — The submission.

**Returns**

- (`dict`) — The submission, with its ``status``, ``errors``, ``error_reason`` and ``external_identifiers``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1308-1325)

## madbot_cli.operations.is_connected

*function*

```python
def is_connected(connection: Mapping) -> bool
```

Tell whether the account has working credentials for a connection.

**Parameters**

- `connection` (`dict`) — A connection as the API returns it.

**Returns**

- (`bool`) — True when its credential is ``connected``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L415-429)

## madbot_cli.operations.is_empty

*function*

```python
def is_empty(value: Any) -> bool
```

Tell whether a metadata value is empty.

**Parameters**

- `value` (`Any`) — The value.

**Returns**

- (`bool`) — True for None, an empty text, an EditorJS text without blocks (as the web client saves a cleared description, with its ``time`` and ``version``), or a mapping or a list whose parts are all empty (none at all included).

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1468-1492)

## madbot_cli.operations.link_data

*function*

```python
def link_data(client: Client, node_id: str, connection_id: str, items: Iterable[Mapping[str, str]], batch_size: int = BATCH_SIZE) -> list[dict]
```

Link data of a source to a node, by batches.

Data already linked to the node are left as they are. madbot then reads
each new data from its source in a background task: wait for it with
`wait_for_data`.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `node_id` (`str`) — The node.
- `connection_id` (`str`) — The connection to the source.
- `items` (`iterable of mapping`) — Each data, as ``{"external_id": ..., "name": ...}``; the name is optional and shown until the data is read.
- `batch_size` (`int`) (default: `BATCH_SIZE`) — Most data sent in one request.

**Returns**

- (`list of dict`) — The answer to each batch: ``task_id``, ``created``, ``existing`` and ``results``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L799-848)

## madbot_cli.operations.list_child_nodes

*function*

```python
def list_child_nodes(client: Client, parent_id: str) -> list[dict]
```

List the nodes right under a node.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `parent_id` (`str`) — The parent node.

**Returns**

- (`list of dict`) — Its child nodes, not their own children.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L133-149)

## madbot_cli.operations.list_datalinks

*function*

```python
def list_datalinks(client: Client, node_id: str, status: str | None = None) -> list[dict]
```

List the data linked to a node.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `node_id` (`str`) — The node.
- `status` (`str`) (default: `None`) — Only the data in this state: ``active``, ``in progress`` or ``failed``.

**Returns**

- (`list of dict`) — The datalinks, each with its ``data`` (``id``, ``name``, ``connection``, ``external_id``, ``status``, ``enrichment_error``).

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L775-796)

## madbot_cli.operations.list_metadata_objects

*function*

```python
def list_metadata_objects(client: Client, submission_id: str) -> list[dict]
```

List the metadata objects of a submission with their values.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `submission_id` (`str`) — The submission.

**Returns**

- (`list of dict`) — Each object with its ``type``, ``summary_fields`` and ``metadata_items``: the field (``slug``, ``level``) and its value.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1428-1447)

## madbot_cli.operations.list_plugins

*function*

```python
def list_plugins(client: Client) -> list[dict]
```

List the plugins of the instance.

**Parameters**

- `client` (`Client`) — The client.

**Returns**

- (`list of dict`) — The plugins, each with its ``id`` (the path a connection names) and its ``slug``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L255-270)

## madbot_cli.operations.list_root_nodes

*function*

```python
def list_root_nodes(client: Client) -> list[dict]
```

List the nodes at the top of the workspace of the client.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.

**Returns**

- (`list of dict`) — The nodes without a parent.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L116-130)

## madbot_cli.operations.list_sample_datalinks

*function*

```python
def list_sample_datalinks(client: Client, node_id: str, sample_id: str) -> set[str]
```

Return the datalinks bound to a sample.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `node_id` (`str`) — The node of the sample.
- `sample_id` (`str`) — The sample.

**Returns**

- (`set of str`) — The identifiers of its datalinks.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L940-959)

## madbot_cli.operations.list_samples

*function*

```python
def list_samples(client: Client, node_id: str) -> list[dict]
```

List the samples of a node.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `node_id` (`str`) — The node.

**Returns**

- (`list of dict`) — The samples, each with its ``id``, ``alias`` and ``title``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L921-937)

## madbot_cli.operations.list_submission_data

*function*

```python
def list_submission_data(client: Client, submission_id: str) -> list[dict]
```

List the data of a submission.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `submission_id` (`str`) — The submission.

**Returns**

- (`list of dict`) — Each data of the submission, with its ``data`` and ``datalink``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1376-1392)

## madbot_cli.operations.list_submissions

*function*

```python
def list_submissions(client: Client) -> list[dict]
```

List the submissions of the workspace of the client.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.

**Returns**

- (`list of dict`) — Each submission, with its ``title``, ``status`` and ``connection``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1207-1221)

## madbot_cli.operations.missing_metadata

*function*

```python
def missing_metadata(client: Client, submission_id: str) -> list[dict]
```

List the metadata objects of a submission that still lack mandatory values.

Give the values with `set_metadata`, object by object. Once none is
left, `generate_metadata` has madbot check the submission as a whole.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `submission_id` (`str`) — The submission, its metadata made (see `wait_submission`).

**Returns**

- (`list of dict`) — Each object with mandatory fields still empty: its ``id``, ``type`` and ``summary_fields`` (such as its alias), and ``missing``, each field (``slug``, ``name``, ``description``) to fill.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1495-1537)

## madbot_cli.operations.object_id

*function*

```python
def object_id(value: Any) -> str | None
```

Return the identifier of an object the API gives either embedded or by identifier.

**Parameters**

- `value` (`Any`) — A dict with an ``id``, an identifier, or None.

**Returns**

- (`str or None`) — The identifier.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L44-60)

## madbot_cli.operations.plan_samples

*function*

```python
def plan_samples(datalinks: Iterable[Mapping], samples: Iterable[Mapping], pattern: re.Pattern | str, bound: Mapping[str, set[str]] | None = None) -> dict
```

Group the data of a node into samples, by the ``sample`` group of a pattern.

Nothing is read nor written: the inputs come from the API.

**Parameters**

- `datalinks` (`iterable of dict`) — The datalinks the samples are made from.
- `samples` (`iterable of dict`) — The samples already on the node, found again by their alias, else by their title.
- `pattern` (`re.Pattern or str`) — A regular expression with a ``sample`` group, searched in each data name.
- `bound` (`mapping`) (default: `None`) — The datalinks already bound to each sample, by sample identifier.

**Returns**

- (`dict`) — ``samples``: one entry per sample, ``{alias, title, exists, sample_id, files: [{name, datalink, data, linked}]}``; ``ignored``: the names that do not match; ``warnings``: names that give the same alias.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L979-1056)

## madbot_cli.operations.plugin_id_of

*function*

```python
def plugin_id_of(connection: Mapping) -> str | None
```

Return the plugin identifier of a connection.

**Parameters**

- `connection` (`dict`) — A connection as the API returns it.

**Returns**

- (`str or None`) — The identifier of its plugin.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L323-337)

## madbot_cli.operations.reads_without_credentials

*function*

```python
def reads_without_credentials(plugin: Mapping) -> bool
```

Tell whether a plugin reads the public data of its source without credentials.

**Parameters**

- `plugin` (`dict`) — A plugin as ``GET /api/plugins`` returns it.

**Returns**

- (`bool`) — True for a data plugin with ``supports_anonymous_access``; false with an API older than this field.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L432-447)

## madbot_cli.operations.resolve_plugin

*function*

```python
def resolve_plugin(plugins: Iterable[Mapping], reference: str) -> dict
```

Find a plugin by its identifier or its slug.

**Parameters**

- `plugins` (`iterable of dict`) — The plugins of the instance, from `list_plugins`.
- `reference` (`str`) — The identifier of the plugin (its Python path) or its slug.

**Returns**

- (`dict`) — The plugin.

**Raises**

- `MadbotError` — When the instance has no such plugin.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L273-300)

## madbot_cli.operations.retry_data

*function*

```python
def retry_data(client: Client, node_id: str, datalink_id: str) -> dict
```

Read again from its source a data madbot failed to read.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `node_id` (`str`) — The node of the datalink.
- `datalink_id` (`str`) — The datalink of the failed data.

**Returns**

- (`dict`) — ``task_id`` of the new reading, and the ``datalink``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L875-893)

## madbot_cli.operations.search

*function*

```python
def search(client: Client, connection_id: str, query: str, parent: str | None = None) -> dict
```

Search the data of a source, one page of results.

A source that serves public data to anyone, such as Zenodo, lists
nothing at its root: its records are found by searching, by identifier,
DOI or title. Follows `GET /api/connections/{id}/external_data/search`.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `connection_id` (`str`) — The connection to the source.
- `query` (`str`) — The text to search, at least `SEARCH_MIN_LENGTH` characters.
- `parent` (`str`) (default: `None`) — The ``id`` of a container to search in; the whole source when None.

**Returns**

- (`dict`) — ``count``, the number of results in all, ``results``, the first page (each object with its ``id``, ``name``, ``type`` and ``has_children``), and ``message``, why it is empty when the source says so.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L537-576)

## madbot_cli.operations.set_metadata

*function*

```python
def set_metadata(client: Client, submission_id: str, object_id: str, values: Mapping[str, Any]) -> list[dict]
```

Give values to fields of a metadata object of a submission, replacing those already there.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `submission_id` (`str`) — The submission.
- `object_id` (`str`) — The metadata object.
- `values` (`mapping`) — Each value by field slug.

**Returns**

- (`list of dict`) — The metadata of the object.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1540-1567)

## madbot_cli.operations.shared_params_of

*function*

```python
def shared_params_of(connection: Mapping) -> dict[str, str]
```

Return the shared parameters of a connection as a mapping.

**Parameters**

- `connection` (`dict`) — A connection as the API returns it.

**Returns**

- (`dict`) — Each shared parameter by its key.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L306-320)

## madbot_cli.operations.submit

*function*

```python
def submit(client: Client, submission_id: str) -> dict
```

Send a ready submission to its repository. This cannot be undone.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `submission_id` (`str`) — The submission, ``ready``.

**Returns**

- (`dict`) — The submission, being submitted: wait for it with `wait_submission`.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1591-1609)

## madbot_cli.operations.wait_for_data

*function*

```python
def wait_for_data(client: Client, task_ids: Iterable[str | None], **wait: Any) -> list[dict]
```

Wait until madbot has read the data of some batches from their sources.

**Parameters**

- `client` (`Client`) — The client.
- `task_ids` (`iterable of str`) — The tasks of the batches; None values are skipped.
- `**wait` (`Any`) (default: `{}`) — Passed to `Client.wait_task`, such as ``timeout``.

**Returns**

- (`list of dict`) — Each task, with its ``result``: ``enriched`` and ``failed`` counts, and the outcome of each data in ``items``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L851-872)

## madbot_cli.operations.wait_submission

*function*

```python
def wait_submission(client: Client, submission_id: str, *, timeout: float = 1800, interval: float = 2, on_wait: Callable[[float], None] | None = None) -> dict
```

Wait until madbot no longer works on a submission in the background.

**Parameters**

- `client` (`Client`) — The client, with its workspace set.
- `submission_id` (`str`) — The submission.
- `timeout` (`float`) (default: `1800`) — Seconds to wait in all.
- `interval` (`float`) (default: `2`) — Seconds between two reads.
- `on_wait` (`callable`) (default: `None`) — Called with the seconds waited so far, before each pause: shows the progress.

**Returns**

- (`dict`) — The submission, neither generating its metadata nor being submitted.

**Raises**

- `WaitTimeout` — When it is still busy after `timeout` seconds.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/operations.py#L1328-1373)
