# `DCATR.Repository.Type`
[🔗](https://github.com/dcat-r/dcatr-ex/blob/v0.1.0/lib/dcatr/model/repository/type.ex#L1)

Behaviour for defining custom repository types with extensible graph catalogs.

`DCATR.Repository`s are the core catalog layer in DCAT-R. This behaviour enables applications to
create specialized repository types with custom graph collections and selector logic.

## Graph Structure

A repository contains:
- **dataset** - Primary catalog of DataGraphs (user data)
- **manifest_graph** - Repository manifest (RepositoryManifestGraph)
- **system_graphs** - Optional repository-level graphs (e.g., history, provenance)

## Callbacks

- `c:system_graphs/1` - Returns additional system-level graphs
- `c:primary_graph/1` - Returns the primary graph if one is designated

Inherits from `DCATR.Directory.Type`:

- `c:DCATR.Directory.Type.graphs/1`, `c:DCATR.Directory.Type.directories/1`

Inherits from `DCATR.GraphResolver`:

- `c:DCATR.GraphResolver.resolve_graph_selector/2`

## Standard Selectors

- `:primary` - Primary graph (when present)
- `:repository_manifest`, `:repo_manifest` - Repository metadata graph

## Usage

Custom repository types should `use DCATR.Repository.Type` and define a Grax schema
extending `DCATR.Repository`:

    defmodule MyApp.Repository do
      use DCATR.Repository.Type

      schema MyApp.NS.Repository < DCATR.Repository do
        link history_graph: MyApp.NS.history(), type: MyApp.HistoryGraph
      end

      @impl true
      def resolve_graph_selector(repo, :history), do: repo.history_graph
      def resolve_graph_selector(repo, selector), do: super(repo, selector)

      @impl true
      def system_graphs(repo) do
        [repo.history_graph | super(repo)]
      end
    end

The module automatically provides delegating implementations of all callbacks
and convenience functions, all of which are overridable.

# `schema`

```elixir
@type schema() :: Grax.Schema.t()
```

# `t`

```elixir
@type t() :: module()
```

# `primary_graph`

```elixir
@callback primary_graph(repository :: schema()) :: DCATR.DataGraph.t() | nil
```

Returns the primary graph if one is designated.

Override to customize primary graph selection.

# `system_graphs`

```elixir
@callback system_graphs(repository :: schema()) :: [DCATR.SystemGraph.t()]
```

Returns all system graphs in the repository.

System graphs are repository-level graphs not part of the primary dataset
(e.g., history graphs, provenance graphs).

Override to include additional system-level graphs specific to your repository type.

# `directories`

```elixir
@spec directories(schema()) :: [DCATR.Dataset.t()]
```

Default implementation of `c:DCATR.Directory.Type.directories/1` for repositories.

Returns the dataset as the sole sub-directory (when present).

# `graphs`

```elixir
@spec graphs(schema()) :: [DCATR.Graph.t()]
```

Default implementation of `c:DCATR.Directory.Type.graphs/1` for repositories.

Returns direct graph members: `data_graph` (when present), manifest, and system graphs.
In multi-graph mode (with dataset), `data_graph` is `nil` and the data graphs are reached
via dataset traversal.

# `primary_graph`

```elixir
@spec primary_graph(schema()) :: DCATR.DataGraph.t() | nil
```

Default implementation of `c:primary_graph/1`.

Returns the `primary_graph` field.

# `resolve_graph_selector`

```elixir
@spec resolve_graph_selector(schema(), DCATR.GraphResolver.selector()) ::
  DCATR.Graph.t() | nil | :undefined
```

Default implementation of `c:DCATR.GraphResolver.resolve_graph_selector/2`.

Resolves repository-specific selectors, then delegates to the dataset for unknown selectors.

Supported selectors:

- `:primary` - Primary graph (when present)
- `:repository_manifest`, `:repo_manifest` - Repository manifest graph

# `system_graphs`

```elixir
@spec system_graphs(schema()) :: [DCATR.SystemGraph.t()]
```

Default implementation of `c:system_graphs/1`.

Returns the `system_graphs` field.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
