/
interface.ex
85 lines (77 loc) · 1.93 KB
/
interface.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
defmodule Ash.Resource.Interface do
@moduledoc """
Represents a function in a resource's code interface
"""
defstruct [:name, :action, :args, :get?]
@type t :: %__MODULE__{}
def interface_options(action_type) do
[
tenant: [
type: :any,
doc: "set the tenant of the query/changeset"
],
context: [
type: :any,
doc: "set context on the query/changeset"
],
actor: [
type: :any,
doc: "set the actor for authorization"
],
authorize?: [
type: :boolean,
doc: """
whether or not to perform authorization.
If an actor option is provided (even if it is `nil`), defaults to `true`. If not, defaults to `false`.
"""
],
verbose?: [
type: :boolean,
doc: "a flag to toggle verbose output from the internal Ash engine (for debugging)"
]
] ++ action_type_opts(action_type)
end
defp action_type_opts(:create) do
[
changeset: [
type: :any,
doc: "A changeset to seed the action with."
]
]
end
defp action_type_opts(:read) do
[
query: [
type: :any,
doc: "A query to seed the action with."
]
]
end
defp action_type_opts(_), do: []
@schema [
name: [
type: :atom,
doc: "The name of the function that will be defined",
required: true
],
action: [
type: :atom,
doc:
"The name of the action that will be called. Defaults to the same name as the function."
],
args: [
type: {:list, :atom},
doc: """
Map specific arguments to named inputs. Can provide any argument/attributes that the action allows.
"""
],
get?: [
type: :boolean,
doc: """
Only relevant for read actions. Expects to only receive a single result from a read action.
For example, `get_user_by_email`.
"""
]
]
def schema, do: @schema
end