Anvil.ForgeBridge behaviour (Anvil v0.1.1)

View Source

Abstract interface for fetching samples from Forge.

Supports multiple backends (direct DB, HTTP, cached) to enable different deployment topologies:

  • Direct: Same Postgres cluster, cross-schema queries
  • HTTP: Separate services with REST API
  • Cached: Performance wrapper with TTL-based caching

Configuration

# config/config.exs
config :anvil,
  forge_bridge_backend: Anvil.ForgeBridge.Direct

Usage

{:ok, sample} = Anvil.ForgeBridge.fetch_sample(sample_id)
%SampleDTO{id: id, content: content, version: version} = sample

Summary

Callbacks

Fetches a single sample from Forge by ID.

Fetches only the version tag for a sample (lightweight query).

Batch fetch multiple samples from Forge.

Verifies if a sample exists in Forge (lightweight check).

Functions

Fetches a single sample using the configured backend.

Fetches sample version using the configured backend.

Batch fetches samples using the configured backend.

Verifies sample existence using the configured backend.

Types

error_reason()

@type error_reason() :: :not_found | :forge_unavailable | atom()

sample_dto()

@type sample_dto() :: Anvil.ForgeBridge.SampleDTO.t()

sample_id()

@type sample_id() :: binary()

Callbacks

fetch_sample(sample_id, opts)

@callback fetch_sample(sample_id(), opts :: keyword()) ::
  {:ok, sample_dto()} | {:error, error_reason()}

Fetches a single sample from Forge by ID.

Options

  • :version - Fetch specific version (optional)
  • :include_metadata - Include full metadata (default: true)

fetch_sample_version(sample_id)

@callback fetch_sample_version(sample_id()) ::
  {:ok, String.t()} | {:error, error_reason()}

Fetches only the version tag for a sample (lightweight query).

fetch_samples(list, opts)

@callback fetch_samples([sample_id()], opts :: keyword()) ::
  {:ok, [sample_dto()]} | {:error, error_reason()}

Batch fetch multiple samples from Forge.

Returns samples in same order as input IDs. Missing samples are omitted.

verify_sample_exists(sample_id)

@callback verify_sample_exists(sample_id()) :: boolean()

Verifies if a sample exists in Forge (lightweight check).

Functions

fetch_sample(sample_id, opts \\ [])

@spec fetch_sample(
  sample_id(),
  keyword()
) :: {:ok, sample_dto()} | {:error, error_reason()}

Fetches a single sample using the configured backend.

fetch_sample_version(sample_id)

@spec fetch_sample_version(sample_id()) ::
  {:ok, String.t()} | {:error, error_reason()}

Fetches sample version using the configured backend.

fetch_samples(sample_ids, opts \\ [])

@spec fetch_samples(
  [sample_id()],
  keyword()
) :: {:ok, [sample_dto()]} | {:error, error_reason()}

Batch fetches samples using the configured backend.

verify_sample_exists(sample_id)

@spec verify_sample_exists(sample_id()) :: boolean()

Verifies sample existence using the configured backend.