DCATR.Repository.Type behaviour (DCAT-R.ex v0.1.0)

Copy Markdown View Source

Behaviour for defining custom repository types with extensible graph catalogs.

DCATR.Repositorys 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

Inherits from DCATR.Directory.Type:

Inherits from DCATR.GraphResolver:

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.

Summary

Callbacks

Returns the primary graph if one is designated.

Returns all system graphs in the repository.

Functions

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

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

Default implementation of primary_graph/1.

Default implementation of system_graphs/1.

Types

schema()

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

t()

@type t() :: module()

Callbacks

primary_graph(repository)

@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(repository)

@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.

Functions

directories(struct)

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

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

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

graphs(repository)

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

Default implementation of 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(struct)

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

Default implementation of primary_graph/1.

Returns the primary_graph field.

resolve_graph_selector(repository, selector)

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

Default implementation of 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(struct)

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

Default implementation of system_graphs/1.

Returns the system_graphs field.