Anvil.ForgeBridge behaviour (Anvil v0.1.1)
View SourceAbstract 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.DirectUsage
{: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
@type error_reason() :: :not_found | :forge_unavailable | atom()
@type sample_dto() :: Anvil.ForgeBridge.SampleDTO.t()
@type sample_id() :: binary()
Callbacks
@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)
@callback fetch_sample_version(sample_id()) :: {:ok, String.t()} | {:error, error_reason()}
Fetches only the version tag for a sample (lightweight query).
@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.
Verifies if a sample exists in Forge (lightweight check).
Functions
@spec fetch_sample( sample_id(), keyword() ) :: {:ok, sample_dto()} | {:error, error_reason()}
Fetches a single sample using the configured backend.
@spec fetch_sample_version(sample_id()) :: {:ok, String.t()} | {:error, error_reason()}
Fetches sample version using the configured backend.
@spec fetch_samples( [sample_id()], keyword() ) :: {:ok, [sample_dto()]} | {:error, error_reason()}
Batch fetches samples using the configured backend.
Verifies sample existence using the configured backend.