Gno.CommitOperation.Type behaviour (Gno v0.1.0)

Copy Markdown View Source

Behaviour for custom commit operation types.

A custom commit operation type can be defined by implementing this behaviour and using the use Gno.CommitOperation.Type macro.

This provides a macro def_commit_operation/2 that can be used to define the Grax schema of the commit operation. The schema should only define properties for configuration that is loaded from the RDF manifest. Runtime state belongs on the Gno.Commit.Processor (via assigns, metadata, etc.), so that middlewares can access it.

Summary

Callbacks

Returns all changes that should be applied in the commit operation.

Handles the case that no effective changes result from the changeset.

Handles state transitions during the commit process.

Prepares the final commit and adding its metadata.

Returns the result of the commit operation.

Rolls back changes when an error occurs during the commit process.

Types

t()

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

Callbacks

all_changes(t)

@callback all_changes(Gno.Commit.Processor.t()) :: %{optional(atom()) => any()}

Returns all changes that should be applied in the commit operation.

This includes the effective changeset and any additional changes that should be applied in the same transaction.

handle_empty_changeset(t, handling, t)

@callback handle_empty_changeset(
  Gno.Commit.Processor.t(),
  handling :: binary(),
  Gno.EffectiveChangeset.t()
) ::
  {:ok, Gno.Commit.Processor.t()}
  | {:skip_transaction, Gno.Commit.Processor.t()}
  | {:error, any()}

Handles the case that no effective changes result from the changeset.

Implementations can in particular implement custom handling of the :on_no_effective_changes option with additional handling values.

handle_step(step, t)

@callback handle_step(step :: atom(), Gno.Commit.Processor.t()) ::
  {:ok, Gno.Commit.Processor.t()}
  | {:error, term()}
  | {:error, term(), Gno.Commit.Processor.t()}

Handles state transitions during the commit process.

prepare_commit(t)

@callback prepare_commit(Gno.Commit.Processor.t()) ::
  {:ok, Gno.Commit.Processor.t()} | {:error, any()}

Prepares the final commit and adding its metadata.

Note, that this callback is called by the default implementation of the handle_step/2 of the :preparation step, allowing its customization. So, it is only needed when this default implementation is reused.

result(t)

@callback result(Gno.Commit.Processor.t()) ::
  {:ok, any(), Gno.Commit.Processor.t()} | {:error, any()}

Returns the result of the commit operation.

rollback(state, t)

@callback rollback(state :: atom(), Gno.Commit.Processor.t()) ::
  {:ok, Gno.Commit.Processor.t()}
  | {:error, term()}
  | {:error, term(), Gno.Commit.Processor.t()}

Rolls back changes when an error occurs during the commit process.

Functions

def_commit_operation(class, list)

(macro)