# orca.views.code

> A module of morca's API.

Where a pipeline's code is: each step's line at the commit a run, or the registration, was built from (`CodeLinks`), for the link beside every step a page shows.

## Structs

### `CodeRef`

```mojo
struct CodeRef
```

A line of a version's code on its host: its URL, where it is (`file.mojo:26`), and the commit.

Implements: `Copyable`, `Defaultable`, `Movable`

Fields:

- `url: String`
- `at: String`
- `commit: String`

#### `__init__`

```mojo
def __init__(out self)
```

#### `__bool__`

```mojo
def __bool__(self) -> Bool
```

### `CodeLinks`

```mojo
struct CodeLinks
```

A version's code on its host: the pipeline's declaration, each step's function and each dista task, from `orca.locate`'s map.

Implements: `Copyable`, `Movable`

Fields:

- `pipeline: CodeRef`
- `steps: Dict[String, CodeRef]`: Step name to its function's line.
- `tasks: List[Tuple[String, CodeRef]]`: A task's function name and its line.

#### `__init__`

```mojo
def __init__(out self)
```

#### `step`

```mojo
def step(self, name: String) -> CodeRef
```

### `RunCode`

```mojo
struct RunCode
```

What a runs table shows of a run's code, at the commit the run ran: its pipeline's declaration, and its failed step and that step's function.

Implements: `Copyable`, `Movable`

Fields:

- `pipeline: CodeRef`
- `failed: String`: The first step that failed, or empty.
- `step: CodeRef`: `failed`'s function, or an empty one.

## Functions

### `code_links`

```mojo
def code_links(mut db: State, pipeline: String, v: Optional[VersionRow]) -> CodeLinks
```

### `code_of`

```mojo
def code_of(mut db: State, mut cache: Dict[String, CodeLinks], pipeline: String, run: Int = Int(0)) -> CodeLinks
```

The code of the version `run` ran or, if it recorded none or there's no run, of the version `pipeline` is registered with; each version's worked out once per `cache`.

### `runs_code`

```mojo
def runs_code(mut db: State, runs: List[RunRow]) -> Dict[Int, RunCode]
```

Each run's `RunCode`, by id: one query for the runs' versions and failed steps, then each version's code (`code_links`) once.

### `pipeline_srcs`

```mojo
def pipeline_srcs(mut db: State, names: List[String]) -> Dict[String, String]
```

Each pipeline's declaration at the version it's registered with, as the URL of its line (`CodeLinks.pipeline`), for those that have one.
