View Source Ash.Resource.Change behaviour (ash v2.18.2)

The behaviour for an action-specific resource change.

init/1 is defined automatically by use Ash.Resource.Change, but can be implemented if you want to validate/transform any options passed to the module.

The main function is change/3. It takes the changeset, any options that were provided when this change was configured on a resource, and the context, which currently only has the actor.

Summary

Callbacks

Runs on each batch result after it is dispatched to the data layer.

Replaces change/3 for batch actions, allowing to optimize changes for bulk actions.

Runs on each batch before it is dispatched to the data layer.

Types

@type context() :: %{
  optional(:actor) => Ash.Resource.record() | nil,
  optional(:tenant) => String.t() | nil,
  optional(:authorize?) => boolean() | nil,
  optional(:tracer) => Ash.Tracer.t() | [Ash.Tracer.t()] | nil,
  optional(any()) => any()
}
@type ref() :: {module(), Keyword.t()} | module()
@type t() :: %Ash.Resource.Change{
  always_atomic?: term(),
  change: term(),
  description: term(),
  on: term(),
  only_when_valid?: term(),
  where: term()
}

Callbacks

Link to this callback

after_atomic(t, t, record, context)

View Source (optional)
@callback after_atomic(Ash.Changeset.t(), Keyword.t(), Ash.Resource.record(), context()) ::
  {:ok, Ash.Resource.record()} | {:error, term()}
Link to this callback

after_batch(changesets_and_results, opts, context)

View Source (optional)
@callback after_batch(
  changesets_and_results :: [{Ash.Changeset.t(), Ash.Resource.record()}],
  opts :: Keyword.t(),
  context :: context()
) ::
  Enumerable.t(
    {:ok, Ash.Resource.record()}
    | {:error, Ash.Error.t()}
    | Ash.Notifier.Notification.t()
  )

Runs on each batch result after it is dispatched to the data layer.

Link to this callback

atomic(t, t, context)

View Source (optional)
@callback atomic(Ash.Changeset.t(), Keyword.t(), context()) ::
  {:atomic, %{required(atom()) => Ash.Expr.t()}}
  | :not_atomic
  | :ok
  | {:error, term()}
Link to this callback

batch_change(changesets, opts, context)

View Source (optional)
@callback batch_change(
  changesets :: [Ash.Changeset.t()],
  opts :: Keyword.t(),
  context :: context()
) :: Enumerable.t(Ash.Changeset.t() | Ash.Notifier.Notification.t())

Replaces change/3 for batch actions, allowing to optimize changes for bulk actions.

Link to this callback

before_batch(changesets, opts, context)

View Source (optional)
@callback before_batch(
  changesets :: [Ash.Changeset.t()],
  opts :: Keyword.t(),
  context :: context()
) :: Enumerable.t(Ash.Changeset.t() | Ash.Notifier.Notification.t())

Runs on each batch before it is dispatched to the data layer.

Link to this callback

change(changeset, opts, context)

View Source (optional)
@callback change(
  changeset :: Ash.Changeset.t(),
  opts :: Keyword.t(),
  context :: context()
) ::
  Ash.Changeset.t()
@callback init(opts :: Keyword.t()) :: {:ok, Keyword.t()} | {:error, term()}