/
manual_destroy.ex
43 lines (37 loc) · 1.22 KB
/
manual_destroy.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
defmodule Ash.Resource.ManualDestroy do
@moduledoc """
A module to implement manual destroy actions.
Note that in the returns of these functions you must return the destroyed record or records.
"""
@type context :: %{
optional(:actor) => term,
optional(:tenant) => term,
optional(:authorize?) => boolean,
optional(:api) => module,
optional(any) => any
}
@callback destroy(
changeset :: Ash.Changeset.t(),
opts :: Keyword.t(),
context :: context()
) ::
{:ok, Ash.Resource.record()}
| {:ok, Ash.Resource.record(), list(Ash.Notifier.Notification.t())}
| {:error, term}
@callback bulk_destroy(
changesets :: Enumerable.t(Ash.Changeset.t()),
opts :: Keyword.t(),
context :: context()
) ::
list(
{:ok, Ash.Resource.record()}
| {:error, Ash.Error.t()}
| {:notifications, list(Ash.Notifier.Notification.t())}
)
@optional_callbacks [bulk_destroy: 3]
defmacro __using__(_) do
quote do
@behaviour Ash.Resource.ManualDestroy
end
end
end