View Source Ash.Api behaviour (ash v2.18.2)
An Api allows you to interact with your resources, and holds non-resource-specific configuration.
For example, the json api extension adds an api extension that lets you toggle authorization on/off for all resources in that Api. You include them in an Api like so:
defmodule MyApp.Registry do
use Ash.Registry
entries do
entry OneResource
entry SecondResource
end
end
defmodule MyApp.Api do
use Ash.Api
resources do
registry MyApp.Registry
end
end
Then you can interact through that Api with the actions that those resources expose.
For example: MyApp.Api.create(changeset)
, or MyApp.Api.read(query)
. Corresponding
actions must be defined in your resources in order to call them through the Api.
Interface
The functions documented here can be used to call any action on any resource in the Api.
For example, MyApi.read(Myresource, [...])
.
Additionally, you can define a code_interface
on each resource. See the code interface guide for more.
Summary
Callbacks
Get the avg of a given field from the given query
Get the avg of a given field from the given query, raising any errors
Creates many records.
Creates many records, raising on any errors. See bulk_create/2
for more.
Destroys all items in the provided enumerable or query with the provided input.
Destroys all items in the provided enumerable or query with the provided input. See bulk_destroy/4
for more.
Updates all items in the provided enumerable or query with the provided input.
Updates all items in the provided enumerable or query with the provided input. See bulk_update/4
for more.
Returns whether or not the user can perform the action, or :maybe
, returning any errors.
Returns whether or not the user can perform the action, or raises on errors.
Create a record.
Create a record. See create/2
for more information.
Destroy a record.
Destroy a record. See destroy/2
for more information.
Whether or not the given query would return any results
Whether or not the given query would return any results, raising any errors
Get the first of a given field from the given query
Get the first of a given field from the given query, raising any errors
Get a record by a primary key.
Get a record by a primary key. See get/3
for more.
Get list of a given field from the given query
Get the list of a given field from the given query, raising any errors
Load fields or relationships on already fetched records.
Load fields or relationships on already fetched records. See load/3
for more information.
Get the max of a given field from the given query
Get the max of a given field from the given query, raising any errors
Get the min of a given field from the given query
Get the min of a given field from the given query, raising any errors
Fetch a page relative to the provided page.
Fetch a page relative to the provided page.
Run a query on a resource.
Run an ash query. See read/2
for more.
Run a query on a resource, but fail on more than one result.
Run an ash query, raising on more than one result. See read_one/2
for more.
Refetches a record by primary key.
Refetches a record by primary key. See reload/1
for more.
Runs a generic action
Runs a generic action, raising on errors
Streams the results of a query.
Get the sum of a given field from the given query
Get the sum of a given field from the given query, raising any errors
Update a record.
Update a record. See update/2
for more information.
Functions
Runs an aggregate or aggregates over a resource query
See Ash.Api.Info.allow/1
.
Evaluates the calculation on the resource.
Runs a generic action.
Types
Callbacks
@callback aggregate( Ash.Query.t(), aggregate() | [aggregate()], opts :: Keyword.t() ) :: {:ok, any()} | {:error, Ash.Error.t()}
@callback avg(Ash.Query.t(), field :: atom(), opts :: Keyword.t()) :: {:ok, term()} | {:error, Ash.Error.t()}
Get the avg of a given field from the given query
@callback avg!(Ash.Query.t(), field :: atom(), opts :: Keyword.t()) :: term() | no_return()
Get the avg of a given field from the given query, raising any errors
@callback bulk_create( [map()], resource :: Ash.Resource.t(), action :: atom(), opts :: Keyword.t() ) :: Ash.BulkResult.t() | Enumerable.t( {:ok, Ash.Resource.record()} | {:error, Ash.Changeset.t() | Ash.Error.t()} | {:notification, Ash.Notifier.Notification.t()} )
Creates many records.
Assumptions
We assume that the input is a list of changesets all for the same action, or a list of input maps for the
same action with the :resource
and :action
option provided to illustrate which action it is for.
Performance/Feasibility
The performance of this operation depends on the data layer in question. Data layers like AshPostgres will choose reasonable batch sizes in an attempt to handle large bulk actions, but that does not mean that you can pass a list of 500k inputs and expect things to go off without a hitch (although it might). If you need to do large data processing, you should look into projects like GenStage and Broadway. With that said, if you want to do things like support CSV upload and you place some reasonable limits on the size this is a great tool. You'll need to test it yourself, YMMV.
Passing return_records?: true
can significantly increase the time it takes to perform the operation,
and can also make the operation completely unreasonable due to the memory requirement. If you want to
do very large bulk creates and display all of the results, the suggestion is to annotate them with a
"bulk_create_id" in the data layer, and then read the records with that bulk_create_id
so that they can
be retrieved later if necessary.
Changes/Validations
Changes will be applied in the order they are given on the actions as normal. Any change that exposes
the bulk_change
or bulk_validate
callback will be applied on the entire list.
After Action Hooks
The following requirements must be met for after_action
hooks to function properly. If they are not met,
and an after_action hook being applied to a changeset in a change
.
return_records?
must be set totrue
.- The changeset must be setting the primary key as part of its changes, so that we know which result applies to which changeset.
It is possible to use after_action
hooks with bulk_change/3
, but you need to return the hooks along with the changesets.
This allows for setting up after_action
hooks that don't need access to the returned record,
or after_action
hooks that can operate on the entire list at once. See the documentation for that callback for more on
how to do accomplish that.
Options
:upsert?
(boolean/0
) - If a conflict is found based on the primary key, the record is updated in the database (requires upsert support) The default value isfalse
.:upsert_identity
(atom/0
) - The identity to use when detecting conflicts forupsert?
, e.g.upsert_identity: :full_name
. By default, the primary key is used. Has no effect ifupsert?: true
is not provided:upsert_fields
- The fields to upsert. If not set, the action'supsert_fields
is used. Unlike singularcreate
,bulk_create
withupsert?
requires thatupsert_fields
be specified explicitly in one of these two locations.:timeout
(timeout/0
) - A positive integer, or:infinity
. If none is provided, the timeout configured on the api is used (which defaults to30_000
).:tracer
- A tracer that implements theAsh.Tracer
behaviour. See that module for more.:verbose?
(boolean/0
) - Log engine operations (very verbose!) The default value isfalse
.:authorize?
- If an actor option is provided (even if it isnil
), authorization happens automatically. If not, this flag can be used to authorize with no user. Valid values are true, false, nil:stacktraces?
(boolean/0
) - For Ash errors, whether or not each error has a stacktrace. See the error_handling guide for more. The default value istrue
.:tenant
(term/0
) - A tenant to set on the query or changeset:actor
(term/0
) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access:return_notifications?
(boolean/0
) - Use this if you're running ash actions in your own transaction and you want notifications to happen still.
If a transaction is ongoing, and this is false, notifications will be discarded, otherwise the return value is{:ok, result, notifications}
(or{:ok, notifications}
)
To send notifications later, useAsh.Notifier.notify(notifications)
. It sends any notifications that can be sent, and returns the rest. The default value isfalse
.:rollback_on_error?
(boolean/0
) - Whether or not to rollback the transaction on error, if the resource is in a transaction.
If the action hastransaction? false
this option has no effect. If an error is returned from the data layer and the resource is in a transaction, the transaction is always rolled back, regardless. The default value istrue
.:notification_metadata
(term/0
) - Metadata to be merged into the metadata field for all notifications sent from this operation. The default value is%{}
.:assume_casted?
(boolean/0
) - Whether or not to cast attributes and arguments as input. This is an optimization for cases where the input is already casted and/or not in need of casting The default value isfalse
.:context
(map/0
) - Context to set on each changeset:sorted?
(boolean/0
) - Whether or not to sort results by their input position, in cases wherereturn_records?: true
was provided. The default value isfalse
.:return_records?
(boolean/0
) - Whether or not to return all of the records that were inserted. Defaults to false to account for large inserts. The default value isfalse
.:return_errors?
(boolean/0
) - Whether or not to return all of the errors that occur. Defaults to false to account for large inserts. The default value isfalse
.:batch_size
(pos_integer/0
) - The number of records to include in each batch. Defaults to thedefault_limit
ormax_page_size
of the action, or 100.:return_stream?
(boolean/0
) - If set totrue
, instead of anAsh.BulkResult
, a mixed stream is returned.
Potential elements:{:notification, notification}
- ifreturn_notifications?
is set totrue
{:ok, record}
- ifreturn_records?
is set totrue
{:error, error}
- an error that occurred. May be changeset or an invidual error. The default value isfalse
.:stop_on_error?
(boolean/0
) - If true, the first encountered error will stop the action and be returned. Otherwise, errors will be skipped. The default value isfalse
.:notify?
(boolean/0
) - Whether or not to send notifications out. If this is set totrue
then the data layer must return the results from each batch. This may be intensive for large bulk actions. The default value isfalse
.:transaction
- Whether or not to wrap the entire execution in a transaction, each batch, or not at all.
Keep in mind:before_transaction
andafter_transaction
hooks attached to changesets will have to be run inside the transaction if you choosetransaction: :all
. Valid values are :all, :batch, false The default value is:batch
.:max_concurrency
(non_neg_integer/0
) - If set to a value greater than 0, up to that many tasks will be started to run batches asynchronously The default value is0
.
@callback bulk_create!( [map()], resource :: Ash.Resource.t(), action :: atom(), opts :: Keyword.t() ) :: Ash.BulkResult.t() | no_return()
Creates many records, raising on any errors. See bulk_create/2
for more.
:upsert?
(boolean/0
) - If a conflict is found based on the primary key, the record is updated in the database (requires upsert support) The default value isfalse
.:upsert_identity
(atom/0
) - The identity to use when detecting conflicts forupsert?
, e.g.upsert_identity: :full_name
. By default, the primary key is used. Has no effect ifupsert?: true
is not provided:upsert_fields
- The fields to upsert. If not set, the action'supsert_fields
is used. Unlike singularcreate
,bulk_create
withupsert?
requires thatupsert_fields
be specified explicitly in one of these two locations.:timeout
(timeout/0
) - A positive integer, or:infinity
. If none is provided, the timeout configured on the api is used (which defaults to30_000
).:tracer
- A tracer that implements theAsh.Tracer
behaviour. See that module for more.:verbose?
(boolean/0
) - Log engine operations (very verbose!) The default value isfalse
.:authorize?
- If an actor option is provided (even if it isnil
), authorization happens automatically. If not, this flag can be used to authorize with no user. Valid values are true, false, nil:stacktraces?
(boolean/0
) - For Ash errors, whether or not each error has a stacktrace. See the error_handling guide for more. The default value istrue
.:tenant
(term/0
) - A tenant to set on the query or changeset:actor
(term/0
) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access:return_notifications?
(boolean/0
) - Use this if you're running ash actions in your own transaction and you want notifications to happen still.
If a transaction is ongoing, and this is false, notifications will be discarded, otherwise the return value is{:ok, result, notifications}
(or{:ok, notifications}
)
To send notifications later, useAsh.Notifier.notify(notifications)
. It sends any notifications that can be sent, and returns the rest. The default value isfalse
.:rollback_on_error?
(boolean/0
) - Whether or not to rollback the transaction on error, if the resource is in a transaction.
If the action hastransaction? false
this option has no effect. If an error is returned from the data layer and the resource is in a transaction, the transaction is always rolled back, regardless. The default value istrue
.:notification_metadata
(term/0
) - Metadata to be merged into the metadata field for all notifications sent from this operation. The default value is%{}
.:assume_casted?
(boolean/0
) - Whether or not to cast attributes and arguments as input. This is an optimization for cases where the input is already casted and/or not in need of casting The default value isfalse
.:context
(map/0
) - Context to set on each changeset:sorted?
(boolean/0
) - Whether or not to sort results by their input position, in cases wherereturn_records?: true
was provided. The default value isfalse
.:return_records?
(boolean/0
) - Whether or not to return all of the records that were inserted. Defaults to false to account for large inserts. The default value isfalse
.:return_errors?
(boolean/0
) - Whether or not to return all of the errors that occur. Defaults to false to account for large inserts. The default value isfalse
.:batch_size
(pos_integer/0
) - The number of records to include in each batch. Defaults to thedefault_limit
ormax_page_size
of the action, or 100.:return_stream?
(boolean/0
) - If set totrue
, instead of anAsh.BulkResult
, a mixed stream is returned.
Potential elements:{:notification, notification}
- ifreturn_notifications?
is set totrue
{:ok, record}
- ifreturn_records?
is set totrue
{:error, error}
- an error that occurred. May be changeset or an invidual error. The default value isfalse
.:stop_on_error?
(boolean/0
) - If true, the first encountered error will stop the action and be returned. Otherwise, errors will be skipped. The default value isfalse
.:notify?
(boolean/0
) - Whether or not to send notifications out. If this is set totrue
then the data layer must return the results from each batch. This may be intensive for large bulk actions. The default value isfalse
.:transaction
- Whether or not to wrap the entire execution in a transaction, each batch, or not at all.
Keep in mind:before_transaction
andafter_transaction
hooks attached to changesets will have to be run inside the transaction if you choosetransaction: :all
. Valid values are :all, :batch, false The default value is:batch
.:max_concurrency
(non_neg_integer/0
) - If set to a value greater than 0, up to that many tasks will be started to run batches asynchronously The default value is0
.
@callback bulk_destroy( Enumerable.t(Ash.Resource.record()) | Ash.Query.t(), atom(), input :: map(), Keyword.t() ) :: Ash.BulkResult.t()
Destroys all items in the provided enumerable or query with the provided input.
If the data layer supports destroying from a query, and the destroy action can be done fully atomically, it will be updated in a single pass using the data layer.
Otherwise, this will stream each record and update it.
Options
:resource
(atom/0
) - The resource being updated. This must be provided if the input given is a stream, so we know ahead of time what the resource being updated is.:stream_batch_size
(integer/0
) - Batch size to use if provided a query and the query must be streamed:allow_stream_with
- The 'worst' strategy allowed to be used to fetch records. SeeAsh.Api.stream!/2
docs for more. Valid values are :keyset, :offset, :full_read The default value is:keyset
.:stream_with
- The specific strategy to use to fetch records. SeeAsh.Api.stream!/2
docs for more. Valid values are :keyset, :offset, :full_read:page
- Pagination options, see the pagination docs for more:load
(term/0
) - A load statement to add onto the query:lock
(term/0
) - A lock statement to add onto the query:return_query?
(boolean/0
) - Iftrue
, the query that was ultimately used is returned as a third tuple element.
The query goes through many potential changes during a request, potentially adding authorization filters, or replacing relationships for other data layers with their corresponding ids. This option can be used to get the true query that was sent to the data layer. The default value isfalse
.:reselect_all?
(boolean/0
) - Whether or not to reselect all attributes depended on by loads. By default, we only reselect fields that weren't already selected. The default value isfalse
.:timeout
(timeout/0
) - A positive integer, or:infinity
. If none is provided, the timeout configured on the api is used (which defaults to30_000
).:tracer
- A tracer that implements theAsh.Tracer
behaviour. See that module for more.:verbose?
(boolean/0
) - Log engine operations (very verbose!) The default value isfalse
.:action
(term/0
) - The action to use, either an Action struct or the name of the action:authorize?
- If an actor option is provided (even if it isnil
), authorization happens automatically. If not, this flag can be used to authorize with no user. Valid values are true, false, nil:stacktraces?
(boolean/0
) - For Ash errors, whether or not each error has a stacktrace. See the error_handling guide for more. The default value istrue
.:tenant
(term/0
) - A tenant to set on the query or changeset:actor
(term/0
) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access:return_notifications?
(boolean/0
) - Use this if you're running ash actions in your own transaction and you want notifications to happen still.
If a transaction is ongoing, and this is false, notifications will be discarded, otherwise the return value is{:ok, result, notifications}
(or{:ok, notifications}
)
To send notifications later, useAsh.Notifier.notify(notifications)
. It sends any notifications that can be sent, and returns the rest. The default value isfalse
.:rollback_on_error?
(boolean/0
) - Whether or not to rollback the transaction on error, if the resource is in a transaction.
If the action hastransaction? false
this option has no effect. If an error is returned from the data layer and the resource is in a transaction, the transaction is always rolled back, regardless. The default value istrue
.:notification_metadata
(term/0
) - Metadata to be merged into the metadata field for all notifications sent from this operation. The default value is%{}
.:assume_casted?
(boolean/0
) - Whether or not to cast attributes and arguments as input. This is an optimization for cases where the input is already casted and/or not in need of casting The default value isfalse
.:context
(map/0
) - Context to set on each changeset:sorted?
(boolean/0
) - Whether or not to sort results by their input position, in cases wherereturn_records?: true
was provided. The default value isfalse
.:return_records?
(boolean/0
) - Whether or not to return all of the records that were inserted. Defaults to false to account for large inserts. The default value isfalse
.:return_errors?
(boolean/0
) - Whether or not to return all of the errors that occur. Defaults to false to account for large inserts. The default value isfalse
.:batch_size
(pos_integer/0
) - The number of records to include in each batch. Defaults to thedefault_limit
ormax_page_size
of the action, or 100.:return_stream?
(boolean/0
) - If set totrue
, instead of anAsh.BulkResult
, a mixed stream is returned.
Potential elements:{:notification, notification}
- ifreturn_notifications?
is set totrue
{:ok, record}
- ifreturn_records?
is set totrue
{:error, error}
- an error that occurred. May be changeset or an invidual error. The default value isfalse
.:stop_on_error?
(boolean/0
) - If true, the first encountered error will stop the action and be returned. Otherwise, errors will be skipped. The default value isfalse
.:notify?
(boolean/0
) - Whether or not to send notifications out. If this is set totrue
then the data layer must return the results from each batch. This may be intensive for large bulk actions. The default value isfalse
.:transaction
- Whether or not to wrap the entire execution in a transaction, each batch, or not at all.
Keep in mind:before_transaction
andafter_transaction
hooks attached to changesets will have to be run inside the transaction if you choosetransaction: :all
. Valid values are :all, :batch, false The default value is:batch
.:max_concurrency
(non_neg_integer/0
) - If set to a value greater than 0, up to that many tasks will be started to run batches asynchronously The default value is0
.
@callback bulk_destroy!( Enumerable.t(Ash.Resource.record()) | Ash.Query.t(), atom(), input :: map(), Keyword.t() ) :: Ash.BulkResult.t() | no_return()
Destroys all items in the provided enumerable or query with the provided input. See bulk_destroy/4
for more.
@callback bulk_update( Enumerable.t(Ash.Resource.record()) | Ash.Query.t(), atom(), input :: map(), Keyword.t() ) :: Ash.BulkResult.t()
Updates all items in the provided enumerable or query with the provided input.
If the data layer supports updating from a query, and the update action can be done fully atomically, it will be updated in a single pass using the data layer.
Otherwise, this will stream each record and update it.
Options
:resource
(atom/0
) - The resource being updated. This must be provided if the input given is a stream, so we know ahead of time what the resource being updated is.:atomic_update
(map/0
) - A map of atomic updates to apply. SeeAsh.Changeset.atomic_update/3
for more.:stream_batch_size
(integer/0
) - Batch size to use if provided a query and the query must be streamed:allow_stream_with
- The 'worst' strategy allowed to be used to fetch records. SeeAsh.Api.stream!/2
docs for more. Valid values are :keyset, :offset, :full_read The default value is:keyset
.:stream_with
- The specific strategy to use to fetch records. SeeAsh.Api.stream!/2
docs for more. Valid values are :keyset, :offset, :full_read:page
- Pagination options, see the pagination docs for more:load
(term/0
) - A load statement to add onto the query:lock
(term/0
) - A lock statement to add onto the query:return_query?
(boolean/0
) - Iftrue
, the query that was ultimately used is returned as a third tuple element.
The query goes through many potential changes during a request, potentially adding authorization filters, or replacing relationships for other data layers with their corresponding ids. This option can be used to get the true query that was sent to the data layer. The default value isfalse
.:reselect_all?
(boolean/0
) - Whether or not to reselect all attributes depended on by loads. By default, we only reselect fields that weren't already selected. The default value isfalse
.:timeout
(timeout/0
) - A positive integer, or:infinity
. If none is provided, the timeout configured on the api is used (which defaults to30_000
).:tracer
- A tracer that implements theAsh.Tracer
behaviour. See that module for more.:verbose?
(boolean/0
) - Log engine operations (very verbose!) The default value isfalse
.:action
(term/0
) - The action to use, either an Action struct or the name of the action:authorize?
- If an actor option is provided (even if it isnil
), authorization happens automatically. If not, this flag can be used to authorize with no user. Valid values are true, false, nil:stacktraces?
(boolean/0
) - For Ash errors, whether or not each error has a stacktrace. See the error_handling guide for more. The default value istrue
.:tenant
(term/0
) - A tenant to set on the query or changeset:actor
(term/0
) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access:return_notifications?
(boolean/0
) - Use this if you're running ash actions in your own transaction and you want notifications to happen still.
If a transaction is ongoing, and this is false, notifications will be discarded, otherwise the return value is{:ok, result, notifications}
(or{:ok, notifications}
)
To send notifications later, useAsh.Notifier.notify(notifications)
. It sends any notifications that can be sent, and returns the rest. The default value isfalse
.:rollback_on_error?
(boolean/0
) - Whether or not to rollback the transaction on error, if the resource is in a transaction.
If the action hastransaction? false
this option has no effect. If an error is returned from the data layer and the resource is in a transaction, the transaction is always rolled back, regardless. The default value istrue
.:notification_metadata
(term/0
) - Metadata to be merged into the metadata field for all notifications sent from this operation. The default value is%{}
.:assume_casted?
(boolean/0
) - Whether or not to cast attributes and arguments as input. This is an optimization for cases where the input is already casted and/or not in need of casting The default value isfalse
.:context
(map/0
) - Context to set on each changeset:sorted?
(boolean/0
) - Whether or not to sort results by their input position, in cases wherereturn_records?: true
was provided. The default value isfalse
.:return_records?
(boolean/0
) - Whether or not to return all of the records that were inserted. Defaults to false to account for large inserts. The default value isfalse
.:return_errors?
(boolean/0
) - Whether or not to return all of the errors that occur. Defaults to false to account for large inserts. The default value isfalse
.:batch_size
(pos_integer/0
) - The number of records to include in each batch. Defaults to thedefault_limit
ormax_page_size
of the action, or 100.:return_stream?
(boolean/0
) - If set totrue
, instead of anAsh.BulkResult
, a mixed stream is returned.
Potential elements:{:notification, notification}
- ifreturn_notifications?
is set totrue
{:ok, record}
- ifreturn_records?
is set totrue
{:error, error}
- an error that occurred. May be changeset or an invidual error. The default value isfalse
.:stop_on_error?
(boolean/0
) - If true, the first encountered error will stop the action and be returned. Otherwise, errors will be skipped. The default value isfalse
.:notify?
(boolean/0
) - Whether or not to send notifications out. If this is set totrue
then the data layer must return the results from each batch. This may be intensive for large bulk actions. The default value isfalse
.:transaction
- Whether or not to wrap the entire execution in a transaction, each batch, or not at all.
Keep in mind:before_transaction
andafter_transaction
hooks attached to changesets will have to be run inside the transaction if you choosetransaction: :all
. Valid values are :all, :batch, false The default value is:batch
.:max_concurrency
(non_neg_integer/0
) - If set to a value greater than 0, up to that many tasks will be started to run batches asynchronously The default value is0
.
@callback bulk_update!( Enumerable.t(Ash.Resource.record()) | Ash.Query.t(), atom(), input :: map(), Keyword.t() ) :: Ash.BulkResult.t() | no_return()
Updates all items in the provided enumerable or query with the provided input. See bulk_update/4
for more.
@callback calculate( resource :: Ash.Resource.t(), calculation :: atom(), opts :: Keyword.t() ) :: {:ok, term()} | {:error, term()}
@callback calculate!( resource :: Ash.Resource.t(), calculation :: atom(), opts :: Keyword.t() ) :: term() | no_return()
@callback can( action_or_query_or_changeset :: Ash.Query.t() | Ash.Changeset.t() | Ash.ActionInput.t() | {Ash.Resource.t(), atom() | Ash.Resource.Actions.action()} | {Ash.Resource.t(), atom() | Ash.Resource.Actions.action(), input :: map()}, actor :: term(), opts :: Keyword.t() ) :: {:ok, boolean() | :maybe} | {:ok, true, Ash.Changeset.t() | Ash.Query.t()} | {:ok, true, Ash.Changeset.t(), Ash.Query.t()} | {:ok, false, Exception.t()} | {:error, term()}
Returns whether or not the user can perform the action, or :maybe
, returning any errors.
In cases with "runtime" checks (checks after the action), we may not be able to determine
an answer, and so the value :maybe
will be returned from can/2
. The can?
function assumes that
:maybe
means true
. Keep in mind, this is just for doing things like "can they do this" in a UI,
so assuming :maybe
is true
is fine. The actual action invocation will be properly checked regardless.
If you have runtime checks, you may need to use can
instead of can?
, or configure what :maybe
means.
Options
maybe_is
- What to treat:maybe
results as, defaults totrue
if usingcan?
, or:maybe
if usingcan
.run_queries?
- In order to determine authorization status for changesets that use filter checks, we may need to run queries (almost always only one query). Set this tofalse
to disable (returning:maybe
instead). The default value istrue
.data
- A record or list of records. For authorizing reads with filter checks, this can be provided and a filter check will only betrue
if all records match the filter. This is detected by running a query.alter_source?
- If true, the query or changeset will be returned with authorization modifications made. For a query, this mans adding field visibility calculations and altering the filter or the sort. For a changeset, this means only adding field visibility calculations. The default value isfalse
.base_query
- If authorizing an update, some cases can return both a new changeset and a query filtered for only things that will be authorized to update. Providing thebase_query
will cause that query to be altered instead of a new one to be generated.
@callback can?( query_or_changeset_or_action :: Ash.Query.t() | Ash.Changeset.t() | Ash.ActionInput.t() | {Ash.Resource.t(), atom() | Ash.Resource.Actions.action()} | {Ash.Resource.t(), atom() | Ash.Resource.Actions.action(), input :: map()}, actor :: term(), opts :: Keyword.t() ) :: boolean() | no_return()
Returns whether or not the user can perform the action, or raises on errors.
See can/3
for more info.
@callback count(Ash.Query.t(), opts :: Keyword.t()) :: {:ok, integer()} | {:error, Ash.Error.t()}
@callback count!(Ash.Query.t(), opts :: Keyword.t()) :: integer() | no_return()
@callback create(Ash.Changeset.t(), opts :: Keyword.t()) :: {:ok, Ash.Resource.record()} | {:ok, Ash.Resource.record(), [Ash.Notifier.Notification.t()]} | {:error, term()}
Create a record.
:upsert?
(boolean/0
) - If a conflict is found based on the primary key, the record is updated in the database (requires upsert support) The default value isfalse
.:upsert_identity
(atom/0
) - The identity to use when detecting conflicts forupsert?
, e.g.upsert_identity: :full_name
. By default, the primary key is used. Has no effect ifupsert?: true
is not provided:upsert_fields
- The fields to upsert. If not set, the action's upsert_fields is used, and if that is not set, then any fields not being set to defaults are written.:timeout
(timeout/0
) - A positive integer, or:infinity
. If none is provided, the timeout configured on the api is used (which defaults to30_000
).:tracer
- A tracer that implements theAsh.Tracer
behaviour. See that module for more.:verbose?
(boolean/0
) - Log engine operations (very verbose!) The default value isfalse
.:action
(term/0
) - The action to use, either an Action struct or the name of the action:authorize?
- If an actor option is provided (even if it isnil
), authorization happens automatically. If not, this flag can be used to authorize with no user. Valid values are true, false, nil:stacktraces?
(boolean/0
) - For Ash errors, whether or not each error has a stacktrace. See the error_handling guide for more. The default value istrue
.:tenant
(term/0
) - A tenant to set on the query or changeset:actor
(term/0
) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access:return_notifications?
(boolean/0
) - Use this if you're running ash actions in your own transaction and you want notifications to happen still.
If a transaction is ongoing, and this is false, notifications will be discarded, otherwise the return value is{:ok, result, notifications}
(or{:ok, notifications}
)
To send notifications later, useAsh.Notifier.notify(notifications)
. It sends any notifications that can be sent, and returns the rest. The default value isfalse
.:rollback_on_error?
(boolean/0
) - Whether or not to rollback the transaction on error, if the resource is in a transaction.
If the action hastransaction? false
this option has no effect. If an error is returned from the data layer and the resource is in a transaction, the transaction is always rolled back, regardless. The default value istrue
.:notification_metadata
(term/0
) - Metadata to be merged into the metadata field for all notifications sent from this operation. The default value is%{}
.
@callback create!(Ash.Changeset.t(), opts :: Keyword.t()) :: Ash.Resource.record() | {Ash.Resource.record(), [Ash.Notifier.Notification.t()]} | no_return()
Create a record. See create/2
for more information.
@callback destroy(Ash.Changeset.t() | Ash.Resource.record(), opts :: Keyword.t()) :: :ok | {:ok, Ash.Resource.record()} | {:ok, [Ash.Notifier.Notification.t()]} | {:ok, Ash.Resource.record(), [Ash.Notifier.Notification.t()]} | {:error, term()}
Destroy a record.
:return_destroyed?
(boolean/0
) - If true, the destroyed record is included in the return result, e.g{:ok, destroyed}
or{:ok, destroyed, notifications}
The default value isfalse
.:timeout
(timeout/0
) - A positive integer, or:infinity
. If none is provided, the timeout configured on the api is used (which defaults to30_000
).:tracer
- A tracer that implements theAsh.Tracer
behaviour. See that module for more.:verbose?
(boolean/0
) - Log engine operations (very verbose!) The default value isfalse
.:action
(term/0
) - The action to use, either an Action struct or the name of the action:authorize?
- If an actor option is provided (even if it isnil
), authorization happens automatically. If not, this flag can be used to authorize with no user. Valid values are true, false, nil:stacktraces?
(boolean/0
) - For Ash errors, whether or not each error has a stacktrace. See the error_handling guide for more. The default value istrue
.:tenant
(term/0
) - A tenant to set on the query or changeset:actor
(term/0
) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access:return_notifications?
(boolean/0
) - Use this if you're running ash actions in your own transaction and you want notifications to happen still.
If a transaction is ongoing, and this is false, notifications will be discarded, otherwise the return value is{:ok, result, notifications}
(or{:ok, notifications}
)
To send notifications later, useAsh.Notifier.notify(notifications)
. It sends any notifications that can be sent, and returns the rest. The default value isfalse
.:rollback_on_error?
(boolean/0
) - Whether or not to rollback the transaction on error, if the resource is in a transaction.
If the action hastransaction? false
this option has no effect. If an error is returned from the data layer and the resource is in a transaction, the transaction is always rolled back, regardless. The default value istrue
.:notification_metadata
(term/0
) - Metadata to be merged into the metadata field for all notifications sent from this operation. The default value is%{}
.
@callback destroy!(Ash.Changeset.t() | Ash.Resource.record(), opts :: Keyword.t()) :: :ok | Ash.Resource.record() | [Ash.Notifier.Notification.t()] | {Ash.Resource.record(), [Ash.Notifier.Notification.t()]} | no_return()
Destroy a record. See destroy/2
for more information.
@callback exists(Ash.Query.t(), opts :: Keyword.t()) :: {:ok, boolean()} | {:error, Ash.Error.t()}
Whether or not the given query would return any results
@callback exists?(Ash.Query.t(), opts :: Keyword.t()) :: boolean() | no_return()
Whether or not the given query would return any results, raising any errors
@callback first(Ash.Query.t(), field :: atom(), opts :: Keyword.t()) :: {:ok, term()} | {:error, Ash.Error.t()}
Get the first of a given field from the given query
@callback first!(Ash.Query.t(), field :: atom(), opts :: Keyword.t()) :: term() | no_return()
Get the first of a given field from the given query, raising any errors
@callback get( resource :: Ash.Resource.t(), id_or_filter :: term(), params :: Keyword.t() ) :: {:ok, Ash.Resource.record()} | {:ok, nil} | {:error, term()}
Get a record by a primary key.
For a resource with a composite primary key, pass a keyword list, e.g
MyApi.get(MyResource, first_key: 1, second_key: 2)
:error?
(boolean/0
) - Whether or not an error should be returned or raised when the record is not found. If set to false,nil
will be returned. The default value istrue
.:load
(term/0
) - Fields or relationships to load in the query. SeeAsh.Query.load/2
:lock
(term/0
) - A lock statement to add onto the query:context
(term/0
) - Context to be set on the query being run:reselect_all?
(boolean/0
) - Whether or not to reselect all attributes depended on by loads. By default, we only reselect fields that weren't already selected. The default value isfalse
.:timeout
(timeout/0
) - A positive integer, or:infinity
. If none is provided, the timeout configured on the api is used (which defaults to30_000
).:tracer
- A tracer that implements theAsh.Tracer
behaviour. See that module for more.:verbose?
(boolean/0
) - Log engine operations (very verbose!) The default value isfalse
.:action
(term/0
) - The action to use, either an Action struct or the name of the action:authorize?
- If an actor option is provided (even if it isnil
), authorization happens automatically. If not, this flag can be used to authorize with no user. Valid values are true, false, nil:stacktraces?
(boolean/0
) - For Ash errors, whether or not each error has a stacktrace. See the error_handling guide for more. The default value istrue
.:tenant
(term/0
) - A tenant to set on the query or changeset:actor
(term/0
) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
@callback get!( resource :: Ash.Resource.t(), id_or_filter :: term(), opts :: Keyword.t() ) :: Ash.Resource.record() | no_return()
Get a record by a primary key. See get/3
for more.
@callback list(Ash.Query.t(), field :: atom(), opts :: Keyword.t()) :: {:ok, [term()]} | {:error, Ash.Error.t()}
Get list of a given field from the given query
@callback list!(Ash.Query.t(), field :: atom(), opts :: Keyword.t()) :: [term()] | no_return()
Get the list of a given field from the given query, raising any errors
@callback load( record_or_records :: Ash.Resource.record() | [Ash.Resource.record()], query :: load_statement(), opts :: Keyword.t() ) :: {:ok, Ash.Resource.record() | [Ash.Resource.record()]} | {:error, term()}
Load fields or relationships on already fetched records.
Accepts a list of non-loaded fields and loads them on the provided records or a query, in
which case the loaded fields of the query are used. Relationship loads can be nested, for
example: MyApi.load(record, [posts: [:comments]])
.
:lazy?
(boolean/0
) - If set to true, values will only be loaded if the related value isn't currently loaded. The default value isfalse
.:reselect_all?
(boolean/0
) - Whether or not to reselect all attributes depended on by loads. By default, we only reselect fields that weren't already selected. The default value isfalse
.:timeout
(timeout/0
) - A positive integer, or:infinity
. If none is provided, the timeout configured on the api is used (which defaults to30_000
).:tracer
- A tracer that implements theAsh.Tracer
behaviour. See that module for more.:verbose?
(boolean/0
) - Log engine operations (very verbose!) The default value isfalse
.:action
(term/0
) - The action to use, either an Action struct or the name of the action:authorize?
- If an actor option is provided (even if it isnil
), authorization happens automatically. If not, this flag can be used to authorize with no user. Valid values are true, false, nil:stacktraces?
(boolean/0
) - For Ash errors, whether or not each error has a stacktrace. See the error_handling guide for more. The default value istrue
.:tenant
(term/0
) - A tenant to set on the query or changeset:actor
(term/0
) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
@callback load!( record_or_records :: Ash.Resource.record() | [Ash.Resource.record()], query :: load_statement(), opts :: Keyword.t() ) :: Ash.Resource.record() | [Ash.Resource.record()] | no_return()
Load fields or relationships on already fetched records. See load/3
for more information.
@callback max(Ash.Query.t(), field :: atom(), opts :: Keyword.t()) :: {:ok, term()} | {:error, Ash.Error.t()}
Get the max of a given field from the given query
@callback max!(Ash.Query.t(), field :: atom(), opts :: Keyword.t()) :: term() | no_return()
Get the max of a given field from the given query, raising any errors
@callback min(Ash.Query.t(), field :: atom(), opts :: Keyword.t()) :: {:ok, term()} | {:error, Ash.Error.t()}
Get the min of a given field from the given query
@callback min!(Ash.Query.t(), field :: atom(), opts :: Keyword.t()) :: term() | no_return()
Get the min of a given field from the given query, raising any errors
@callback page(Ash.Page.page(), page_request()) :: {:ok, Ash.Page.page()} | {:error, term()}
Fetch a page relative to the provided page.
A page is the return value of a paginated action called via read/2
.
@callback page!(Ash.Page.page(), page_request()) :: Ash.Page.page() | no_return()
Fetch a page relative to the provided page.
@callback read(Ash.Query.t(), opts :: Keyword.t()) :: {:ok, [Ash.Resource.record()]} | {:ok, [Ash.Resource.record()], Ash.Query.t()} | {:error, term()}
Run a query on a resource.
For more information on building a query, see Ash.Query
.
:page
- Pagination options, see the pagination docs for more:load
(term/0
) - A load statement to add onto the query:lock
(term/0
) - A lock statement to add onto the query:return_query?
(boolean/0
) - Iftrue
, the query that was ultimately used is returned as a third tuple element.
The query goes through many potential changes during a request, potentially adding authorization filters, or replacing relationships for other data layers with their corresponding ids. This option can be used to get the true query that was sent to the data layer. The default value isfalse
.:reselect_all?
(boolean/0
) - Whether or not to reselect all attributes depended on by loads. By default, we only reselect fields that weren't already selected. The default value isfalse
.:timeout
(timeout/0
) - A positive integer, or:infinity
. If none is provided, the timeout configured on the api is used (which defaults to30_000
).:tracer
- A tracer that implements theAsh.Tracer
behaviour. See that module for more.:verbose?
(boolean/0
) - Log engine operations (very verbose!) The default value isfalse
.:action
(term/0
) - The action to use, either an Action struct or the name of the action:authorize?
- If an actor option is provided (even if it isnil
), authorization happens automatically. If not, this flag can be used to authorize with no user. Valid values are true, false, nil:stacktraces?
(boolean/0
) - For Ash errors, whether or not each error has a stacktrace. See the error_handling guide for more. The default value istrue
.:tenant
(term/0
) - A tenant to set on the query or changeset:actor
(term/0
) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
Pagination
Limit/offset pagination
:offset
(non_neg_integer/0
) - The number of records to skip from the beginning of the query:limit
(pos_integer/0
) - The number of records to include in the page:filter
(term/0
) - A filter to apply for pagination purposes, that should not be considered in the full count.
This is used by the liveview paginator to only fetch the records that were already on the page when refreshing data, to avoid pages jittering.:count
(boolean/0
) - Whether or not to return the page with a full count of all records
Keyset pagination
:before
(String.t/0
) - Get records that appear before the provided keyset (mutually exclusive withafter
):after
(String.t/0
) - Get records that appear after the provided keyset (mutually exclusive withbefore
):limit
(pos_integer/0
) - How many records to include in the page:filter
(term/0
) - See thefilter
option for offset pagination, this behaves the same.:count
(boolean/0
) - Whether or not to return the page with a full count of all records
@callback read!(Ash.Query.t() | Ash.Resource.t(), opts :: Keyword.t()) :: [Ash.Resource.record()] | {[Ash.Resource.record()], Ash.Query.t()} | no_return()
Run an ash query. See read/2
for more.
@callback read_one(Ash.Query.t() | Ash.Resource.t(), opts :: Keyword.t()) :: {:ok, Ash.Resource.record()} | {:ok, Ash.Resource.record(), Ash.Query.t()} | {:ok, nil} | {:error, term()}
Run a query on a resource, but fail on more than one result.
This is useful if you have a query that doesn't include a primary key but you know that it will only ever return a single result.
@callback read_one!(Ash.Query.t() | Ash.Resource.t(), opts :: Keyword.t()) :: Ash.Resource.record() | {Ash.Resource.record(), Ash.Query.t()} | nil | no_return()
Run an ash query, raising on more than one result. See read_one/2
for more.
@callback reload(record :: Ash.Resource.record()) :: {:ok, Ash.Resource.record()} | {:error, term()}
Refetches a record by primary key.
@callback reload!(record :: Ash.Resource.record(), params :: Keyword.t()) :: Ash.Resource.record() | no_return()
Refetches a record by primary key. See reload/1
for more.
@callback run_action(input :: Ash.ActionInput.t(), opts :: Keyword.t()) :: {:ok, term()} | {:error, term()}
Runs a generic action
@callback run_action!(input :: Ash.ActionInput.t(), opts :: Keyword.t()) :: term() | no_return()
Runs a generic action, raising on errors
@callback stream!(Ash.Query.t(), opts :: Keyword.t()) :: Enumerable.t(Ash.Resource.record())
Streams the results of a query.
Strategies
There are three strategies supported, and the best one available is always chosen. They are, in order from best to worst:
:keyset
:offset
:full_read
By default, only :keyset
is supported. If you want to allow worse strategies to be used, pass
the worst one you wish to allow as the allow_stream_with
option, i.e allow_stream_with: :full_read
.
If you wish to specify a specific strategy to use, pass stream_with: :strategy_name
.
Keyset
This utilizes keyset pagination to accomplish this stream. The action must support keyset pagination. This is the most efficient way to stream a query, because it works by using filters which can benefit from indexes in the data layer.
Offset
This utilizes offset/limit to accomplish this stream. If the action supports offset pagination, that will
be used. Otherwise, if the data layer supports limit/offset, then explicit limits/offsets will be used.
This is a much less efficient way of streaming a resource than keyset
. To use limit/offset to reliably
stream, a sort must always be applied, and limit/offset in the data layer will generally require sorting
the entire table to figure out what is in each batch.
Full Read
This reads the entire table into memory with no limit. This is, generally speaking, the least efficient.
Options
:batch_size
(integer/0
) - How many records to request in each query run. Defaults to the pagination limits on the resource, or 250.:allow_stream_with
- The 'worst' strategy allowed to be used to fetch records. SeeAsh.Api.stream!/2
docs for more. Valid values are :keyset, :offset, :full_read The default value is:keyset
.:stream_with
- The specific strategy to use to fetch records. SeeAsh.Api.stream!/2
docs for more. Valid values are :keyset, :offset, :full_read:page
- Pagination options, see the pagination docs for more:load
(term/0
) - A load statement to add onto the query:lock
(term/0
) - A lock statement to add onto the query:return_query?
(boolean/0
) - Iftrue
, the query that was ultimately used is returned as a third tuple element.
The query goes through many potential changes during a request, potentially adding authorization filters, or replacing relationships for other data layers with their corresponding ids. This option can be used to get the true query that was sent to the data layer. The default value isfalse
.:reselect_all?
(boolean/0
) - Whether or not to reselect all attributes depended on by loads. By default, we only reselect fields that weren't already selected. The default value isfalse
.:timeout
(timeout/0
) - A positive integer, or:infinity
. If none is provided, the timeout configured on the api is used (which defaults to30_000
).:tracer
- A tracer that implements theAsh.Tracer
behaviour. See that module for more.:verbose?
(boolean/0
) - Log engine operations (very verbose!) The default value isfalse
.:action
(term/0
) - The action to use, either an Action struct or the name of the action:authorize?
- If an actor option is provided (even if it isnil
), authorization happens automatically. If not, this flag can be used to authorize with no user. Valid values are true, false, nil:stacktraces?
(boolean/0
) - For Ash errors, whether or not each error has a stacktrace. See the error_handling guide for more. The default value istrue
.:tenant
(term/0
) - A tenant to set on the query or changeset:actor
(term/0
) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
@callback sum(Ash.Query.t(), field :: atom(), opts :: Keyword.t()) :: {:ok, term()} | {:error, Ash.Error.t()}
Get the sum of a given field from the given query
@callback sum!(Ash.Query.t(), field :: atom(), opts :: Keyword.t()) :: term() | no_return()
Get the sum of a given field from the given query, raising any errors
@callback update(Ash.Changeset.t(), opts :: Keyword.t()) :: {:ok, Ash.Resource.record()} | {:ok, Ash.Resource.record(), [Ash.Notifier.Notification.t()]} | {:error, term()}
Update a record.
:timeout
(timeout/0
) - A positive integer, or:infinity
. If none is provided, the timeout configured on the api is used (which defaults to30_000
).:tracer
- A tracer that implements theAsh.Tracer
behaviour. See that module for more.:verbose?
(boolean/0
) - Log engine operations (very verbose!) The default value isfalse
.:action
(term/0
) - The action to use, either an Action struct or the name of the action:authorize?
- If an actor option is provided (even if it isnil
), authorization happens automatically. If not, this flag can be used to authorize with no user. Valid values are true, false, nil:stacktraces?
(boolean/0
) - For Ash errors, whether or not each error has a stacktrace. See the error_handling guide for more. The default value istrue
.:tenant
(term/0
) - A tenant to set on the query or changeset:actor
(term/0
) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access:return_notifications?
(boolean/0
) - Use this if you're running ash actions in your own transaction and you want notifications to happen still.
If a transaction is ongoing, and this is false, notifications will be discarded, otherwise the return value is{:ok, result, notifications}
(or{:ok, notifications}
)
To send notifications later, useAsh.Notifier.notify(notifications)
. It sends any notifications that can be sent, and returns the rest. The default value isfalse
.:rollback_on_error?
(boolean/0
) - Whether or not to rollback the transaction on error, if the resource is in a transaction.
If the action hastransaction? false
this option has no effect. If an error is returned from the data layer and the resource is in a transaction, the transaction is always rolled back, regardless. The default value istrue
.:notification_metadata
(term/0
) - Metadata to be merged into the metadata field for all notifications sent from this operation. The default value is%{}
.
@callback update!(Ash.Changeset.t(), opts :: Keyword.t()) :: Ash.Resource.record() | {Ash.Resource.record(), [Ash.Notifier.Notification.t()]} | no_return()
Update a record. See update/2
for more information.
Functions
@spec aggregate( api :: t(), Ash.Query.t() | Ash.Resource.t(), aggregates :: aggregate() | [aggregate()], opts :: Keyword.t() ) :: {:ok, term()} | {:error, Ash.Error.t()}
Runs an aggregate or aggregates over a resource query
:timeout
(timeout/0
) - A positive integer, or:infinity
. If none is provided, the timeout configured on the api is used (which defaults to30_000
).:tracer
- A tracer that implements theAsh.Tracer
behaviour. See that module for more.:verbose?
(boolean/0
) - Log engine operations (very verbose!) The default value isfalse
.:action
(term/0
) - The action to use, either an Action struct or the name of the action:authorize?
- If an actor option is provided (even if it isnil
), authorization happens automatically. If not, this flag can be used to authorize with no user. Valid values are true, false, nil:stacktraces?
(boolean/0
) - For Ash errors, whether or not each error has a stacktrace. See the error_handling guide for more. The default value istrue
.:tenant
(term/0
) - A tenant to set on the query or changeset:actor
(term/0
) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access
See Ash.Api.Info.allow/1
.
Evaluates the calculation on the resource.
If a record is provided, its field values will be used to evaluate the calculation.
:args
(map/0
) - Values for arguments referenced by the calculation. The default value is%{}
.:refs
(map/0
) - Values for references used by the calculation. The default value is%{}
.:actor
(term/0
) - The actor for handling^actor/1
templates, supplied to calculation context.:tenant
(term/0
) - The tenant, supplied to calculation context.:authorize?
(boolean/0
) - Whether or not the request is being authorized, provided to calculation context. The default value istrue
.:tracer
- A tracer, provided to the calculation context.:record
(term/0
) - A record to use as the base of the calculation
@spec can( api :: t(), action_or_query_or_changeset :: Ash.Query.t() | Ash.Changeset.t() | Ash.ActionInput.t() | {Ash.Resource.t(), atom() | Ash.Resource.Actions.action()} | {Ash.Resource.t(), atom() | Ash.Resource.Actions.action(), input :: map()}, actor :: term(), opts :: Keyword.t() ) :: {:ok, boolean() | :maybe} | {:ok, true, Ash.Changeset.t() | Ash.Query.t()} | {:ok, true, Ash.Changeset.t(), Ash.Query.t()} | {:ok, false, Exception.t()} | {:error, term()}
@spec can?( api :: t(), query_or_changeset_or_action :: Ash.Query.t() | Ash.Changeset.t() | Ash.ActionInput.t() | {Ash.Resource.t(), atom() | Ash.Resource.Actions.action()} | {Ash.Resource.t(), atom() | Ash.Resource.Actions.action(), input :: map()}, actor :: term(), opts :: Keyword.t() ) :: boolean() | no_return()
@spec run_action(api :: t(), input :: Ash.ActionInput.t(), opts :: Keyword.t()) :: {:ok, term()} | {:error, Ash.Error.t()}
Runs a generic action.
Options:
@spec run_action!(api :: t(), input :: Ash.ActionInput.t(), opts :: Keyword.t()) :: term() | no_return()
@spec stream!(api :: module(), query :: Ash.Query.t(), opts :: Keyword.t()) :: Enumerable.t(Ash.Resource.record())