What a resource package's UI needs from the proxy at run time, as a
behaviour: the page's own way of reading and writing records
(Alternera.Resource.UI.Records calls it), and messages between a
package's components.
A package compiles before the proxy and cannot name its modules. The
proxy's implementation is Alternera.Resources.UIHost, set with
config :alternera_resource_ui, :host, …; a package's own tests run
against Alternera.Resource.UI.Test.Host, which calls Ash directly.
Every callback takes the component's Alternera.Resource.UI.Context
and a resource module, and reads or writes with the context's tenant and
actor, so the resource's policies decide. Every {:error, _} is logged
before it is returned.
Summary
Callbacks
Sends message to the components subscribed to topic, on every node.
The topic is already scoped to the package and tenant
(Alternera.Resource.UI.broadcast/3).
Creates a record through the resource's primary create action.
Deletes a record; refused while other records refer to it.
An error's messages, %{field, message}, field nil for a record-wide one.
A record by id or lookup key; {:error, :not_found} without one.
A page of records: {:ok, %{records, count}}. Options: :search (a text
the simple search looks for in :search_in, a list of attribute names,
by default the resource's list fields), :filter (attribute to value),
:sort ([{attribute, :asc | :desc}]), :limit (at most 200, default
Restores the record a version holds.
Updates a record through the resource's primary update action.
A record's versions, newest first.
Types
Callbacks
Sends message to the components subscribed to topic, on every node.
The topic is already scoped to the package and tenant
(Alternera.Resource.UI.broadcast/3).
@callback create(Alternera.Resource.UI.Context.t(), module(), map()) :: {:ok, struct()} | {:error, term()}
Creates a record through the resource's primary create action.
@callback delete(Alternera.Resource.UI.Context.t(), module(), struct()) :: :ok | {:error, term()}
Deletes a record; refused while other records refer to it.
An error's messages, %{field, message}, field nil for a record-wide one.
@callback get(Alternera.Resource.UI.Context.t(), module(), ref()) :: {:ok, struct()} | {:error, term()}
A record by id or lookup key; {:error, :not_found} without one.
@callback list(Alternera.Resource.UI.Context.t(), module(), keyword()) :: {:ok, %{records: list(), count: non_neg_integer()}} | {:error, term()}
A page of records: {:ok, %{records, count}}. Options: :search (a text
the simple search looks for in :search_in, a list of attribute names,
by default the resource's list fields), :filter (attribute to value),
:sort ([{attribute, :asc | :desc}]), :limit (at most 200, default
- and
:offset.
@callback restore(Alternera.Resource.UI.Context.t(), module(), struct()) :: {:ok, struct()} | {:error, term()}
Restores the record a version holds.
@callback update(Alternera.Resource.UI.Context.t(), module(), struct(), map()) :: {:ok, struct()} | {:error, term()}
Updates a record through the resource's primary update action.
@callback versions(Alternera.Resource.UI.Context.t(), module(), term()) :: {:ok, list()} | {:error, term()}
A record's versions, newest first.
Functions
@spec impl() :: module()
The configured host module.