Behaviour that all SferaDoc storage backends must implement.
Templates are identified by their name (a human-readable string). Each name
can have multiple numbered versions; at most one version per name is active at
any time.
Implementing a Custom Adapter
useor@behaviour SferaDoc.Store.AdapterImplement all callbacks
Return
nilfromworker_spec/0if your adapter uses an externally supervised process (e.g. an Ecto Repo managed by the host application)Configure the library to use your adapter:
config :sfera_doc, :store, adapter: MyApp.CustomAdapter
Summary
Callbacks
Makes the given version the active one for the template name. Deactivates all other versions for that name.
Deletes all versions of a template by name.
Fetches the currently active template for the given name.
Fetches a specific version of a template by name and version number.
Returns all templates (latest active version per name).
Returns all versions for a given template name, ordered by version descending.
Persists a new version of the template.
Returns a child spec for processes this adapter needs, or nil if the
adapter relies on externally managed processes (e.g. Ecto repos).
Types
Callbacks
@callback activate_version(name(), version()) :: {:ok, SferaDoc.Template.t()} | {:error, :not_found} | {:error, reason()}
Makes the given version the active one for the template name. Deactivates all other versions for that name.
Deletes all versions of a template by name.
@callback get(name()) :: {:ok, SferaDoc.Template.t()} | {:error, :not_found} | {:error, reason()}
Fetches the currently active template for the given name.
@callback get_version(name(), version()) :: {:ok, SferaDoc.Template.t()} | {:error, :not_found} | {:error, reason()}
Fetches a specific version of a template by name and version number.
@callback list() :: {:ok, [SferaDoc.Template.t()]} | {:error, reason()}
Returns all templates (latest active version per name).
@callback list_versions(name()) :: {:ok, [SferaDoc.Template.t()]} | {:error, reason()}
Returns all versions for a given template name, ordered by version descending.
@callback put(SferaDoc.Template.t()) :: {:ok, SferaDoc.Template.t()} | {:error, reason()}
Persists a new version of the template.
The adapter is responsible for:
- computing the next version number (
MAX(existing versions) + 1, or1if new) - setting
is_active: trueon the new record - setting
is_active: falseon all previous versions for the same name
Both create and update go through this single callback.
@callback worker_spec() :: Supervisor.child_spec() | nil
Returns a child spec for processes this adapter needs, or nil if the
adapter relies on externally managed processes (e.g. Ecto repos).
The supervisor filters out nil values, so returning nil is safe.