# `Smee.MDQ`
[🔗](https://github.com/Digital-Identity-Labs/smee/blob/main/lib/smee/mdq.ex#L1)

`Smee.MDQ` provides a client API to MDQ services, and also attempts to emulate MDQ-style behaviour with old-fashioned
  metadata aggregates. MDQ allows individual entities to be looked up when needed without downloading and processing
  an increasingly enormous metadata aggregate file.

Emulation of MDQ for aggregates depends on caching and is usually slower for individual entity lookups even after the
  initial download and caching is complete.

# `aggregate!`
[🔗](https://github.com/Digital-Identity-Labs/smee/blob/main/lib/smee/mdq.ex#L67)

```elixir
@spec aggregate!(source :: Smee.Source.t()) :: Smee.Metadata.t()
```

Returns the aggregated XML for the MDQ service as a Metadata struct, if one is available.

# `get`
[🔗](https://github.com/Digital-Identity-Labs/smee/blob/main/lib/smee/mdq.ex#L77)

```elixir
@spec get(source :: Smee.Source.t(), entity_id :: binary()) :: Smee.Entity.t() | nil
```

Fetches an individual entity's metadata from the MDQ service and returns it as an Entity struct.

Get attempts to behave like Ecto's `Repo.get` - it will return an entity or nil if the entity is unavailable.

# `get!`
[🔗](https://github.com/Digital-Identity-Labs/smee/blob/main/lib/smee/mdq.ex#L93)

```elixir
@spec get!(source :: Smee.Source.t(), entity_id :: binary()) :: Smee.Entity.t()
```

Fetches an individual entity's metadata from the MDQ service and returns it as an Entity struct.

Get attempts to behave like Ecto's `Repo.get!` - it will return an entity or raises an exception if the entity is unavailable.

This is identical to `lookup!2` but exists for consistency.

# `list!`
[🔗](https://github.com/Digital-Identity-Labs/smee/blob/main/lib/smee/mdq.ex#L35)

```elixir
@spec list!(source :: Smee.Source.t()) :: [binary()]
```

Returns a list of all entity ID URIs available at the MDQ service.

This will probably involve downloading the MDQ service's aggregate in most cases, but this aggregate will be cached.

# `lookup`
[🔗](https://github.com/Digital-Identity-Labs/smee/blob/main/lib/smee/mdq.ex#L103)

```elixir
@spec lookup(source :: Smee.Source.t(), entity_id :: binary()) ::
  {:ok, Smee.Entity.t()} | {:error, any()}
```

Fetches an individual entity's metadata from the MDQ service and returns it as an Entity struct in an :ok/:error tuple.

Missing or unknown entities will cause an {:error, :http_404} result.

# `lookup!`
[🔗](https://github.com/Digital-Identity-Labs/smee/blob/main/lib/smee/mdq.ex#L130)

```elixir
@spec lookup!(source :: Smee.Source.t(), entity_id :: binary()) :: Smee.Entity.t()
```

Fetches an individual entity's metadata from the MDQ service and returns it as an Entity struct.

This is identical to `get!2` but exists for consistency.

# `source`
[🔗](https://github.com/Digital-Identity-Labs/smee/blob/main/lib/smee/mdq.ex#L24)

```elixir
@spec source(url :: binary(), options :: keyword()) :: Smee.Source.t()
```

A convenient shortcut for specifying an MDQ service as a source.

This is functionally identical to using `Smee.Source.new(url, type: :mdq)`

# `stream`
[🔗](https://github.com/Digital-Identity-Labs/smee/blob/main/lib/smee/mdq.ex#L163)

```elixir
@spec stream(source :: Smee.Source.t()) :: Enumerable.t()
```

Fetches *every entity* from the MDQ service one by one and returns them as a stream of Entity structs.

This stream allows entities to be processed individually, using relatively little memory.

The stream is relatively laid-back even on a fast M1 Mac, but please don't abuse this function and overwhelm public MDQ
  services.

# `stream`
[🔗](https://github.com/Digital-Identity-Labs/smee/blob/main/lib/smee/mdq.ex#L177)

```elixir
@spec stream(source :: Smee.Source.t(), ids :: list()) :: Enumerable.t()
```

Fetches the specified entities from the MDQ service one by one and returns them as a stream of Entity structs.

This stream allows entities to be processed individually, using relatively little memory.

The stream is relatively laid-back even on a fast M1 Mac, but please don't abuse this function and overwhelm public MDQ
  services.

# `transform_uri`
[🔗](https://github.com/Digital-Identity-Labs/smee/blob/main/lib/smee/mdq.ex#L195)

```elixir
@spec transform_uri(entity_id :: binary()) :: binary()
```

If passed an entity ID URI is returns the MDQ "transformed" version of the identifer, based on a sha1 hash.

Already-transformed identifiers are passed through unchanged.

# `url`
[🔗](https://github.com/Digital-Identity-Labs/smee/blob/main/lib/smee/mdq.ex#L51)

```elixir
@spec url(source :: Smee.Source.t(), entity_id :: binary()) :: binary()
```

Returns the full download URL for an entity at the specified service.

---

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