From bef705861333013e725d49c136b4d349e6ad8368 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Thu, 14 Sep 2023 16:48:49 -0400 Subject: [PATCH] chore: remove DSLs, no need to commit generated content --- documentation/dsls/DSL:-Ash.Api.cheatmd | 153 - .../dsls/DSL:-Ash.DataLayer.Ets.cheatmd | 37 - .../dsls/DSL:-Ash.DataLayer.Mnesia.cheatmd | 40 - documentation/dsls/DSL:-Ash.Flow.cheatmd | 633 ---- .../dsls/DSL:-Ash.Notifier.PubSub.cheatmd | 124 - .../dsls/DSL:-Ash.Policy.Authorizer.cheatmd | 865 ------ documentation/dsls/DSL:-Ash.Registry.cheatmd | 65 - documentation/dsls/DSL:-Ash.Resource.cheatmd | 2627 ----------------- 8 files changed, 4544 deletions(-) delete mode 100644 documentation/dsls/DSL:-Ash.Api.cheatmd delete mode 100644 documentation/dsls/DSL:-Ash.DataLayer.Ets.cheatmd delete mode 100644 documentation/dsls/DSL:-Ash.DataLayer.Mnesia.cheatmd delete mode 100644 documentation/dsls/DSL:-Ash.Flow.cheatmd delete mode 100644 documentation/dsls/DSL:-Ash.Notifier.PubSub.cheatmd delete mode 100644 documentation/dsls/DSL:-Ash.Policy.Authorizer.cheatmd delete mode 100644 documentation/dsls/DSL:-Ash.Registry.cheatmd delete mode 100644 documentation/dsls/DSL:-Ash.Resource.cheatmd diff --git a/documentation/dsls/DSL:-Ash.Api.cheatmd b/documentation/dsls/DSL:-Ash.Api.cheatmd deleted file mode 100644 index 9846929e..00000000 --- a/documentation/dsls/DSL:-Ash.Api.cheatmd +++ /dev/null @@ -1,153 +0,0 @@ -# DSL: Ash.Api.Dsl - -Apis are the entrypoints for working with your resources. - -Apis may optionally include a list of resources, in which case they can be -used as an `Ash.Registry` in various places. This is for backwards compatibility, -but if at all possible you should define an `Ash.Registry` if you are using an extension -that requires a list of resources. For example, most extensions look for two application -environment variables called `:ash_apis` and `:ash_registries` to find any potential registries - - -## api -General Api configuration - ---- - - - -### Examples -``` -api do - description """ - Resources related to the flux capacitor. - """ -end - -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `description` | `String.t` | A description for the api. | - - - - - - -## resources -List the resources present in this API - ---- - - * [resource](#resources-resource) - -### Examples -``` -resources do - resource MyApp.Tweet - resource MyApp.Comment -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `allow` | `mfa` | | Support a dynamic resource list by providing a callback that checks whether or not the resource should be allowed. | -| `allow_unregistered?` | `boolean` | false | Whether the Api will support only registered entries or not. | -| `registry` | `module` | | Configure a registry that contains the resources. This option is generally not necessary anymore, and remains for backwards compatibility. Instead, configure resources in this block directly. | - - - -## resources.resource - -```elixir -resource resource -``` - ---- - -Introspection Target: `Ash.Api.Dsl.ResourceReference` - -A resource present in the API - ---- - - - -### Examples -``` -resource Foo -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `resource` - required-arg 1 | `module` | | - - - - - - - -## execution -Options for how requests are executed using this Api - ---- - - - -### Examples -``` -execution do - timeout :timer.seconds(30) -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `timeout` | `timeout` | 30000 | The default timeout to use for requests using this API. See the [timeouts guide](/documentation/topics/timeouts.md) for more. | -| `trace_name` | `String.t` | | The name to use in traces. Defaults to the last part of the module. See the [monitoring guide](/documentation/topics/monitoring.md) for more | - - - - - - -## authorization -Options for how requests are authorized using this Api. See the [security guide](/documentation/topics/security.md) for more. - - ---- - - - -### Examples -``` -authorization do - authorize :by_default -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `require_actor?` | `boolean` | false | Requires that an actor has been supplied. | -| `authorize` | `:always \| :by_default \| :when_requested` | :when_requested | When to run authorization for a given request. | - - - - - - diff --git a/documentation/dsls/DSL:-Ash.DataLayer.Ets.cheatmd b/documentation/dsls/DSL:-Ash.DataLayer.Ets.cheatmd deleted file mode 100644 index 101cb73d..00000000 --- a/documentation/dsls/DSL:-Ash.DataLayer.Ets.cheatmd +++ /dev/null @@ -1,37 +0,0 @@ -# DSL: Ash.DataLayer.Ets - -An ETS (Erlang Term Storage) backed Ash Datalayer, for testing and lightweight usage. - -Remember, this does not have support for transactions! This is not recommended for production -use, especially in multi-user applications. It can, however, be great for prototyping. - - -## ets -A section for configuring the ets data layer - - ---- - - - -### Examples -``` -ets do - # Used in testing - private? true -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `private?` | `boolean` | false | Sets the ets table protection to private, and scopes it to only this process. The table name will not be used directly if this is true, to allow multiple processes to use this resource separately. | -| `table` | `atom` | | The name of the table. Defaults to the resource name. | - - - - - - diff --git a/documentation/dsls/DSL:-Ash.DataLayer.Mnesia.cheatmd b/documentation/dsls/DSL:-Ash.DataLayer.Mnesia.cheatmd deleted file mode 100644 index 98a963ba..00000000 --- a/documentation/dsls/DSL:-Ash.DataLayer.Mnesia.cheatmd +++ /dev/null @@ -1,40 +0,0 @@ -# DSL: Ash.DataLayer.Mnesia - -An Mnesia backed Ash Datalayer. - -In your application initialization, you will need to call `Mnesia.create_schema([node()])`. - -Additionally, you will want to create your mnesia tables there. - -This data layer is *unoptimized*, fetching all records from a table and filtering them -in memory. For that reason, it is not recommended to use it with large amounts of data. It can be -great for prototyping or light usage, though. - - -## mnesia -A section for configuring the mnesia data layer - - ---- - - - -### Examples -``` -mnesia do - table :custom_table -end - -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `table` | `atom` | The table name to use, defaults to the name of the resource | - - - - - - diff --git a/documentation/dsls/DSL:-Ash.Flow.cheatmd b/documentation/dsls/DSL:-Ash.Flow.cheatmd deleted file mode 100644 index f1ef09a9..00000000 --- a/documentation/dsls/DSL:-Ash.Flow.cheatmd +++ /dev/null @@ -1,633 +0,0 @@ -# DSL: Ash.Flow.Dsl - -The built in flow DSL. - -## Halting - -Steps can be halted, which will stop the flow from continuing and return a halted flow. To attach a specific reason, use a `halt_reason`. -If you need more complex halting logic, then you'd want to use a custom step, and return `{:error, Ash.Error.Flow.Halted.exception(...)}` - - -## flow -Details about the flow itself, like description and the successful return type. - - ---- - - * [argument](#flow-argument) - -### Examples - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `api` | `module` | An api to use by default when calling actions | -| `description` | `String.t` | A description of the flow | -| `trace_name` | `String.t` | The name to use when creating traces. Defaults to the short name. | -| `short_name` | `atom` | A short name to use for the flow. Defaults to the last to parts of the module name, underscored. | -| `returns` | ``any`` | The step or step that should constitute the return value. | - - - -## flow.argument - -```elixir -argument name, type -``` - ---- - -Introspection Target: `Ash.Flow.Argument` - -An argument to be passed into the flow - - ---- - - - -### Examples -``` -argument :params, :map do - default %{} -end - -``` - - -``` -argument :retries, :integer do - allow_nil? false -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name to use for the argument | -| `type` - required-arg 2 | `module` | | The type of the argument. See `Ash.Type` for more. | -| `default` | `(-> any) \| mfa \| any()` | | A default value to use for the argument if not provided | -| `allow_nil?` | `boolean` | true | Whether or not the argument value may be nil | -| `constraints` | `Keyword.t` | [] | Constraints to provide to the type when casting the value. See the type's documentation for more information. | - - - - - - - -## steps - ---- - - * [map](#steps-map) - - * [branch](#steps-branch) - - * [transaction](#steps-transaction) - - * [create](#steps-create) - * [debug](#steps-debug) - * [update](#steps-update) - * [destroy](#steps-destroy) - * [validate](#steps-validate) - * [read](#steps-read) - * [run_flow](#steps-run_flow) - * [custom](#steps-custom) - -### Examples -``` -steps do - # invokes a create action - create :create_post, MyApp.Post, :create -end - -``` - - - -## steps.map - -```elixir -map name, over -``` - ---- - -Introspection Target: `Ash.Flow.Step.Map` - -Runs a set of steps for each item in a provided list. - - ---- - - - -### Examples -``` -map :create_users, range(1, arg(:count)) do - output :create_user - - create :create_user, Org, :create do - input %{ - first_name: {Faker.Person, :first_name, []}, - last_name: {Faker.Person, :last_name, []} - } - end -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the step. Will be used when expressing dependencies, and step inputs. | -| `over` - arg 2 | ``any`` | | The value to be iterated over. Will be available inside the `map` step as `element(:map_step_name)` | -| `output` | `atom` | | Which step to use when constructing the output list. Defaults to the last step. | -| `short_name` | `String.t` | | Set a short name for the step. Will be used when building things like mermaid charts. | -| `wait_for` | ``any`` | | Ensures that the step happens after the configured step or steps. This is a template who's results are not used, only awaited. | -| `touches_resources` | `list(atom)` | | A list of resources touched by any custom logic in this step. This is used in the case that this step is run in a transaction. This is primarily only needed for `custom` steps. | -| `halt_if` | ``any`` | | Halts the step by emitting an error (with an `Ash.Error.Flow.Halted`). Can use template variables. See the section on Halting for more. | -| `halt_reason` | ``any`` | :halted | Configures the reason for the `halt_if` clause. | -| `description` | `String.t` | | A description for the step. | - - - - -## steps.branch - -```elixir -branch name, condition -``` - ---- - -Introspection Target: `Ash.Flow.Step.Branch` - -Runs a set of steps based on a given value. - - ---- - - - -### Examples -``` -branch :create_users, result(:create_users?) do - output :create_user - - create :create_user, Org, :create do - input %{ - first_name: {Faker.Person, :first_name, []}, - last_name: {Faker.Person, :last_name, []} - } - end -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the step. Will be used when expressing dependencies, and step inputs. | -| `condition` - arg 2 | ``any`` | | A template that must evaluate to `true` for the branch to be executed. | -| `output` | `atom` | | Which step to use as the output. Defaults to the last step. | -| `short_name` | `String.t` | | Set a short name for the step. Will be used when building things like mermaid charts. | -| `wait_for` | ``any`` | | Ensures that the step happens after the configured step or steps. This is a template who's results are not used, only awaited. | -| `touches_resources` | `list(atom)` | | A list of resources touched by any custom logic in this step. This is used in the case that this step is run in a transaction. This is primarily only needed for `custom` steps. | -| `halt_if` | ``any`` | | Halts the step by emitting an error (with an `Ash.Error.Flow.Halted`). Can use template variables. See the section on Halting for more. | -| `halt_reason` | ``any`` | :halted | Configures the reason for the `halt_if` clause. | -| `description` | `String.t` | | A description for the step. | - - - - -## steps.transaction - -```elixir -transaction name, resource -``` - ---- - -Introspection Target: `Ash.Flow.Step.Transaction` - -Runs a set of steps in a transaction. - - ---- - - - -### Examples -``` -transaction :create_users do - create :create_user, User, :create do - input %{ - first_name: {Faker.Person, :first_name, []}, - last_name: {Faker.Person, :last_name, []} - } - end - - create :create_user, Org, :create do - input %{ - first_name: {Faker.Person, :first_name, []}, - last_name: {Faker.Person, :last_name, []} - } - end -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the step. Will be used when expressing dependencies, and step inputs. | -| `resource` - arg 2 | `module \| list(module)` | | The Ash resource to use for the transaction. | -| `output` | ``any`` | | Which step or steps to use when constructing the output. Defaults to the last step. | -| `timeout` | `timeout` | | A timeout to apply to the transaction. | -| `short_name` | `String.t` | | Set a short name for the step. Will be used when building things like mermaid charts. | -| `wait_for` | ``any`` | | Ensures that the step happens after the configured step or steps. This is a template who's results are not used, only awaited. | -| `touches_resources` | `list(atom)` | | A list of resources touched by any custom logic in this step. This is used in the case that this step is run in a transaction. This is primarily only needed for `custom` steps. | -| `halt_if` | ``any`` | | Halts the step by emitting an error (with an `Ash.Error.Flow.Halted`). Can use template variables. See the section on Halting for more. | -| `halt_reason` | ``any`` | :halted | Configures the reason for the `halt_if` clause. | -| `description` | `String.t` | | A description for the step. | - - - - -## steps.create - -```elixir -create name, resource, action -``` - ---- - -Introspection Target: `Ash.Flow.Step.Create` - -Declares a step that will call a create action on a resource. - - ---- - - - -### Examples -``` -create :create_post, MyApp.Post, :create - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the step. Will be used when expressing dependencies, and step inputs. | -| `resource` - required-arg 2 | ``any`` | | The resource to call the action on. | -| `action` - required-arg 3 | ``any`` | | The action to call on the resource. | -| `upsert?` | `boolean` | false | Wether or not this action is always an upsert. | -| `upsert_identity` | `atom` | | The identity to use for the upsert. | -| `short_name` | `String.t` | | Set a short name for the step. Will be used when building things like mermaid charts. | -| `wait_for` | ``any`` | | Ensures that the step happens after the configured step or steps. This is a template who's results are not used, only awaited. | -| `touches_resources` | `list(atom)` | | A list of resources touched by any custom logic in this step. This is used in the case that this step is run in a transaction. This is primarily only needed for `custom` steps. | -| `halt_if` | ``any`` | | Halts the step by emitting an error (with an `Ash.Error.Flow.Halted`). Can use template variables. See the section on Halting for more. | -| `halt_reason` | ``any`` | :halted | Configures the reason for the `halt_if` clause. | -| `description` | `String.t` | | A description for the step. | -| `api` | ``any`` | | The api to use when calling the action. Defaults to the api set in the `flow` section. | -| `tenant` | ``any`` | | A tenant to use for the operation. May be a template or a literal value. | -| `input` | ``any`` | | A template for the input. | - - - - -## steps.debug - -```elixir -debug name -``` - ---- - -Introspection Target: `Ash.Flow.Step.Debug` - -Declares a step that will inspect its input and provide -additional debug information. - - ---- - - - -### Examples -``` -debug :show_some_information do - input %{post: result(:create_post)} -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the step. Will be used when expressing dependencies, and step inputs. | -| `input` | ``any`` | | A template for the input. | -| `short_name` | `String.t` | | Set a short name for the step. Will be used when building things like mermaid charts. | -| `wait_for` | ``any`` | | Ensures that the step happens after the configured step or steps. This is a template who's results are not used, only awaited. | -| `halt_if` | ``any`` | | Halts the step by emitting an error (with an `Ash.Error.Flow.Halted`). Can use template variables. See the section on Halting for more. | -| `halt_reason` | ``any`` | :halted | Configures the reason for the `halt_if` clause. | -| `description` | `String.t` | | A description for the step. | - - - - -## steps.update - -```elixir -update name, resource, action -``` - ---- - -Introspection Target: `Ash.Flow.Step.Update` - -Declares a step that will call a update action on a resource. - - ---- - - - -### Examples -``` -update :update_post, MyApp.Post, :update do - record result(:get_post) -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the step. Will be used when expressing dependencies, and step inputs. | -| `resource` - required-arg 2 | ``any`` | | The resource to call the action on. | -| `action` - required-arg 3 | ``any`` | | The action to call on the resource. | -| `record` - required | ``any`` | | The record to be updated, can use template helpers, e.g `result(:step_name)`. | -| `short_name` | `String.t` | | Set a short name for the step. Will be used when building things like mermaid charts. | -| `wait_for` | ``any`` | | Ensures that the step happens after the configured step or steps. This is a template who's results are not used, only awaited. | -| `touches_resources` | `list(atom)` | | A list of resources touched by any custom logic in this step. This is used in the case that this step is run in a transaction. This is primarily only needed for `custom` steps. | -| `halt_if` | ``any`` | | Halts the step by emitting an error (with an `Ash.Error.Flow.Halted`). Can use template variables. See the section on Halting for more. | -| `halt_reason` | ``any`` | :halted | Configures the reason for the `halt_if` clause. | -| `description` | `String.t` | | A description for the step. | -| `api` | ``any`` | | The api to use when calling the action. Defaults to the api set in the `flow` section. | -| `tenant` | ``any`` | | A tenant to use for the operation. May be a template or a literal value. | -| `input` | ``any`` | | A template for the input. | - - - - -## steps.destroy - -```elixir -destroy name, resource, action -``` - ---- - -Introspection Target: `Ash.Flow.Step.Destroy` - -Declares a step that will call a destroy action on a resource. - - ---- - - - -### Examples -``` -destroy :destroy_post, MyApp.Post, :destroy - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the step. Will be used when expressing dependencies, and step inputs. | -| `resource` - required-arg 2 | ``any`` | | The resource to call the action on. | -| `action` - required-arg 3 | ``any`` | | The action to call on the resource. | -| `record` - required | ``any`` | | The record to be updated, can use template helpers, e.g `result(:step_name)`. | -| `short_name` | `String.t` | | Set a short name for the step. Will be used when building things like mermaid charts. | -| `wait_for` | ``any`` | | Ensures that the step happens after the configured step or steps. This is a template who's results are not used, only awaited. | -| `touches_resources` | `list(atom)` | | A list of resources touched by any custom logic in this step. This is used in the case that this step is run in a transaction. This is primarily only needed for `custom` steps. | -| `halt_if` | ``any`` | | Halts the step by emitting an error (with an `Ash.Error.Flow.Halted`). Can use template variables. See the section on Halting for more. | -| `halt_reason` | ``any`` | :halted | Configures the reason for the `halt_if` clause. | -| `description` | `String.t` | | A description for the step. | -| `api` | ``any`` | | The api to use when calling the action. Defaults to the api set in the `flow` section. | -| `tenant` | ``any`` | | A tenant to use for the operation. May be a template or a literal value. | -| `input` | ``any`` | | A template for the input. | - - - - -## steps.validate - -```elixir -validate name, resource, action -``` - ---- - -Introspection Target: `Ash.Flow.Step.Update` - -Validates some input against an action. - - ---- - - - -### Examples -``` -validate :update_post, MyApp.Post, :update do - record result(:get_post) - only_keys [:name] -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the step. Will be used when expressing dependencies, and step inputs. | -| `resource` - required-arg 2 | ``any`` | | The resource to call the action on. | -| `action` - required-arg 3 | ``any`` | | The action to call on the resource. | -| `record` | ``any`` | | The record to be created/updated/destroyed. If the value is `nil` and would be required by the action type, the step is skipped and `nil` is the result of the step. | -| `only_keys` | `list(atom \| list(atom))` | | A list of keys or paths to keys that should be validated. Others will be ignored, and errors generated for other fields will be ignored. | -| `short_name` | `String.t` | | Set a short name for the step. Will be used when building things like mermaid charts. | -| `wait_for` | ``any`` | | Ensures that the step happens after the configured step or steps. This is a template who's results are not used, only awaited. | -| `touches_resources` | `list(atom)` | | A list of resources touched by any custom logic in this step. This is used in the case that this step is run in a transaction. This is primarily only needed for `custom` steps. | -| `halt_if` | ``any`` | | Halts the step by emitting an error (with an `Ash.Error.Flow.Halted`). Can use template variables. See the section on Halting for more. | -| `halt_reason` | ``any`` | :halted | Configures the reason for the `halt_if` clause. | -| `description` | `String.t` | | A description for the step. | -| `api` | ``any`` | | The api to use when calling the action. Defaults to the api set in the `flow` section. | -| `tenant` | ``any`` | | A tenant to use for the operation. May be a template or a literal value. | -| `input` | ``any`` | | A template for the input. | - - - - -## steps.read - -```elixir -read name, resource, action -``` - ---- - -Introspection Target: `Ash.Flow.Step.Read` - -Declares a step that will call a read action on a resource. - - ---- - - - -### Examples -``` -read :destroy_post, MyApp.Post, :destroy - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the step. Will be used when expressing dependencies, and step inputs. | -| `resource` - required-arg 2 | ``any`` | | The resource to call the action on. | -| `action` - required-arg 3 | ``any`` | | The action to call on the resource. | -| `get?` | `boolean` | false | Whether or not read action is expected to return a single result or `nil`. Set to `true` automatically if `get? true`. | -| `not_found_error?` | `boolean` | true | Whether or not finding no record should result in a not found error | -| `short_name` | `String.t` | | Set a short name for the step. Will be used when building things like mermaid charts. | -| `wait_for` | ``any`` | | Ensures that the step happens after the configured step or steps. This is a template who's results are not used, only awaited. | -| `touches_resources` | `list(atom)` | | A list of resources touched by any custom logic in this step. This is used in the case that this step is run in a transaction. This is primarily only needed for `custom` steps. | -| `halt_if` | ``any`` | | Halts the step by emitting an error (with an `Ash.Error.Flow.Halted`). Can use template variables. See the section on Halting for more. | -| `halt_reason` | ``any`` | :halted | Configures the reason for the `halt_if` clause. | -| `description` | `String.t` | | A description for the step. | -| `api` | ``any`` | | The api to use when calling the action. Defaults to the api set in the `flow` section. | -| `tenant` | ``any`` | | A tenant to use for the operation. May be a template or a literal value. | -| `input` | ``any`` | | A template for the input. | - - - - -## steps.run_flow - -```elixir -run_flow name, flow -``` - ---- - -Introspection Target: `Ash.Flow.Step.RunFlow` - -Runs another flow as part of the current flow. -The return value of the step is the return value of the flow. - - ---- - - - -### Examples -``` -run_flow :get_org, GetOrgByName do - input %{ - name: arg(:org_name) - } - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the step. Will be used when expressing dependencies, and step inputs. | -| `flow` - required-arg 2 | `atom` | | The flow to run. | -| `input` | ``any`` | | A template for the input. | -| `short_name` | `String.t` | | Set a short name for the step. Will be used when building things like mermaid charts. | -| `wait_for` | ``any`` | | Ensures that the step happens after the configured step or steps. This is a template who's results are not used, only awaited. | -| `touches_resources` | `list(atom)` | | A list of resources touched by any custom logic in this step. This is used in the case that this step is run in a transaction. This is primarily only needed for `custom` steps. | -| `halt_if` | ``any`` | | Halts the step by emitting an error (with an `Ash.Error.Flow.Halted`). Can use template variables. See the section on Halting for more. | -| `halt_reason` | ``any`` | :halted | Configures the reason for the `halt_if` clause. | -| `description` | `String.t` | | A description for the step. | - - - - -## steps.custom - -```elixir -custom name, custom -``` - ---- - -Introspection Target: `Ash.Flow.Step.Custom` - -Runs a custom step module. - -See `Ash.Flow.Step` for the necessary callbacks and more information. - - ---- - - - -### Examples -``` -custom :do_custom_thing, MyApp.DoCustomThing do - input %{...} -end - -``` - - -``` -custom :do_custom_thing, {MyApp.DoCustomThing, opt1: :foo, opt2: :bar} do - input %{...} -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the step. Will be used when expressing dependencies, and step inputs. | -| `custom` - arg 2 | `(any, any -> any) \| module` | | The module that implements the step behaviour. Also accepts a 2 argument function that takes the input and the context. | -| `input` | ``any`` | | A template for the input. | -| `async?` | `boolean` | false | Whether or not this step can be run outside of the current process. | -| `short_name` | `String.t` | | Set a short name for the step. Will be used when building things like mermaid charts. | -| `wait_for` | ``any`` | | Ensures that the step happens after the configured step or steps. This is a template who's results are not used, only awaited. | -| `touches_resources` | `list(atom)` | | A list of resources touched by any custom logic in this step. This is used in the case that this step is run in a transaction. This is primarily only needed for `custom` steps. | -| `halt_if` | ``any`` | | Halts the step by emitting an error (with an `Ash.Error.Flow.Halted`). Can use template variables. See the section on Halting for more. | -| `halt_reason` | ``any`` | :halted | Configures the reason for the `halt_if` clause. | -| `description` | `String.t` | | A description for the step. | - - - - - - - diff --git a/documentation/dsls/DSL:-Ash.Notifier.PubSub.cheatmd b/documentation/dsls/DSL:-Ash.Notifier.PubSub.cheatmd deleted file mode 100644 index 29575dc8..00000000 --- a/documentation/dsls/DSL:-Ash.Notifier.PubSub.cheatmd +++ /dev/null @@ -1,124 +0,0 @@ -# DSL: Ash.Notifier.PubSub - -A pubsub notifier extension. - - -## pub_sub -A section for configuring how resource actions are published over pubsub - -See the [PubSub](/documentation/topics/pub_sub.md) and [Notifiers](/documentation/topics/notifiers.md) guide for more. - - ---- - - * [publish](#pub_sub-publish) - * [publish_all](#pub_sub-publish_all) - -### Examples -``` -pub_sub do - module MyEndpoint - prefix "post" - broadcast_type :phoenix_broadcast - - publish :destroy, ["foo", :id] - publish :update, ["bar", :name] event: "name_change" - publish_all :create, "created" -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `module` - required | `atom` | | The module to call `broadcast/3` on e.g module.broadcast(topic, event, message). | -| `prefix` | `String.t` | | A prefix for all pubsub messages, e.g `users`. A message with `created` would be published as `users:created` | -| `broadcast_type` | `:notification \| :phoenix_broadcast \| :broadcast` | :notification | What shape the event payloads will be in. See | -| `name` | `atom` | | A named pub sub to pass as the first argument to broadcast. | - - - -## pub_sub.publish - -```elixir -publish action, topic -``` - ---- - -Introspection Target: `Ash.Notifier.PubSub.Publication` - -Configure a given action to publish its results over a given topic. - -See the [PubSub](/documentation/topics/pub_sub.md) and [Notifiers](/documentation/topics/notifiers.md) guides for more. - - ---- - - - -### Examples -``` -publish :create, "created" -``` - - -``` -publish :assign, "assigned" - -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `action` - required-arg 1 | `atom` | The name of the action that should be published | -| `topic` - required-arg 2 | ``any`` | The topic to publish | -| `event` | `String.t` | The name of the event to publish. Defaults to the action name | -| `dispatcher` | `atom` | The module to use as a dispatcher. If none is set, the pubsub module provided is used. | - - - - -## pub_sub.publish_all - -```elixir -publish_all type, topic -``` - ---- - -Introspection Target: `Ash.Notifier.PubSub.Publication` - -Works just like `publish`, except that it takes a type -and publishes all actions of that type - -See the [PubSub](/documentation/topics/pub_sub.md) and [Notifiers](/documentation/topics/notifiers.md) guides for more. - - ---- - - - -### Examples -``` -publish_all :create, "created" -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `type` - arg 1 | `:create \| :update \| :destroy` | Publish on all actions of a given type | -| `topic` - required-arg 2 | ``any`` | The topic to publish | -| `action` | `atom` | The name of the action that should be published | -| `event` | `String.t` | The name of the event to publish. Defaults to the action name | -| `dispatcher` | `atom` | The module to use as a dispatcher. If none is set, the pubsub module provided is used. | - - - - - - - diff --git a/documentation/dsls/DSL:-Ash.Policy.Authorizer.cheatmd b/documentation/dsls/DSL:-Ash.Policy.Authorizer.cheatmd deleted file mode 100644 index 43d46a78..00000000 --- a/documentation/dsls/DSL:-Ash.Policy.Authorizer.cheatmd +++ /dev/null @@ -1,865 +0,0 @@ -# DSL: Ash.Policy.Authorizer - -An authorization extension for ash resources. - -To add this extension to a resource, add it to the list of `authorizers` like so: - -```elixir -use Ash.Resource, - ..., - authorizers: [ - Ash.Policy.Authorizer - ] -``` - -A resource can be given a set of policies, which are enforced on each call to a resource action. - -For reads, policies can be configured to filter out data that the actor shouldn't see, as opposed to -resulting in a forbidden error. - -See the [policies guide](/documentation/topics/policies.md) for practical examples. - -Policies are solved/managed via a boolean satisfiability solver. To read more about boolean satisfiability, -see this page: https://en.wikipedia.org/wiki/Boolean_satisfiability_problem. At the end of -the day, however, it is not necessary to understand exactly how Ash takes your -authorization requirements and determines if a request is allowed. The -important thing to understand is that Ash may or may not run any/all of your -authorization rules as they may be deemed unnecessary. As such, authorization -checks should have no side effects. Ideally, the checks built-in to ash should -cover the bulk of your needs. - - -## policies -A section for declaring authorization policies. - -Each policy that applies must pass independently in order for the -request to be authorized. - -See the [policies guide](/documentation/topics/policies.md) for more. - - ---- - - * [policy](#policies-policy) - * authorize_if - * forbid_if - * authorize_unless - * forbid_unless - * [bypass](#policies-bypass) - * authorize_if - * forbid_if - * authorize_unless - * forbid_unless - -### Examples -``` -policies do - # Anything you can use in a condition, you can use in a check, and vice-versa - # This policy applies if the actor is a super_user - # Additionally, this policy is declared as a `bypass`. That means that this check is allowed to fail without - # failing the whole request, and that if this check *passes*, the entire request passes. - bypass actor_attribute_equals(:super_user, true) do - authorize_if always() - end - - # This will likely be a common occurrence. Specifically, policies that apply to all read actions - policy action_type(:read) do - # unless the actor is an active user, forbid their request - forbid_unless actor_attribute_equals(:active, true) - # if the record is marked as public, authorize the request - authorize_if attribute(:public, true) - # if the actor is related to the data via that data's `owner` relationship, authorize the request - authorize_if relates_to_actor_via(:owner) - end -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `default_access_type` | `:strict \| :filter \| :runtime` | :filter | The default access type of policies for this resource. | - - - -## policies.policy - -```elixir -policy condition -``` - ---- - -Introspection Target: `Ash.Policy.Policy` - -A policy has a name, a condition, and a list of checks. - -Checks apply logically in the order they are specified, from top to bottom. -If no check explicitly authorizes the request, then the request is forbidden. -This means that, if you want to "blacklist" instead of "whitelist", you likely -want to add an `authorize_if always()` at the bottom of your policy, like so: - -```elixir -policy action_type(:read) do - forbid_if not_logged_in() - forbid_if user_is_denylisted() - forbid_if user_is_in_denylisted_group() - - authorize_if always() -end -``` - -If the policy should always run, use the `always()` check, like so: - -```elixir -policy always() do - ... -end -``` - -See the [policies guide](/documentation/topics/policies.md) for more. - - ---- - - * [authorize_if](#policies-policy-authorize_if) - * [forbid_if](#policies-policy-forbid_if) - * [authorize_unless](#policies-policy-authorize_unless) - * [forbid_unless](#policies-policy-forbid_unless) - -### Examples - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `condition` - arg 1 | ``any`` | A check or list of checks that must be true in order for this policy to apply. | -| `description` | `String.t` | A description for the policy, used when explaining authorization results | -| `access_type` | `:strict \| :filter \| :runtime` | What portion of the checks inside the policy are allowed to run. See the guide for more. | - - -## policies.policy.authorize_if - -```elixir -authorize_if check -``` - ---- - -Introspection Target: `Ash.Policy.Check` - -If the check is true, the request is authorized, otherwise run remaining checks. - ---- - - - -### Examples -``` -authorize_if logged_in() -``` - - -``` -authorize_if actor_attribute_matches_record(:group, :group) -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `check` - required-arg 1 | ``any`` | The check to run. See `Ash.Policy.Check` for more. | -| `name` | `String.t` | A short name or description for the check, used when explaining authorization results | - - - - -## policies.policy.forbid_if - -```elixir -forbid_if check -``` - ---- - -Introspection Target: `Ash.Policy.Check` - -If the check is true, the request is forbidden, otherwise run remaining checks. - ---- - - - -### Examples -``` -forbid_if not_logged_in() -``` - - -``` -forbid_if actor_attribute_matches_record(:group, :blacklisted_groups) -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `check` - required-arg 1 | ``any`` | The check to run. See `Ash.Policy.Check` for more. | -| `name` | `String.t` | A short name or description for the check, used when explaining authorization results | - - - - -## policies.policy.authorize_unless - -```elixir -authorize_unless check -``` - ---- - -Introspection Target: `Ash.Policy.Check` - -If the check is false, the request is authorized, otherwise run remaining checks. - ---- - - - -### Examples -``` -authorize_unless not_logged_in() -``` - - -``` -authorize_unless actor_attribute_matches_record(:group, :blacklisted_groups) -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `check` - required-arg 1 | ``any`` | The check to run. See `Ash.Policy.Check` for more. | -| `name` | `String.t` | A short name or description for the check, used when explaining authorization results | - - - - -## policies.policy.forbid_unless - -```elixir -forbid_unless check -``` - ---- - -Introspection Target: `Ash.Policy.Check` - -If the check is true, the request is forbidden, otherwise run remaining checks. - ---- - - - -### Examples -``` -forbid_unless logged_in() -``` - - -``` -forbid_unless actor_attribute_matches_record(:group, :group) -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `check` - required-arg 1 | ``any`` | The check to run. See `Ash.Policy.Check` for more. | -| `name` | `String.t` | A short name or description for the check, used when explaining authorization results | - - - - - - -## policies.bypass - -```elixir -bypass condition -``` - ---- - -Introspection Target: `Ash.Policy.Policy` - -A policy that, if passed, will skip all following policies. If failed, authorization moves on to the next policy - ---- - - * [authorize_if](#policies-bypass-authorize_if) - * [forbid_if](#policies-bypass-forbid_if) - * [authorize_unless](#policies-bypass-authorize_unless) - * [forbid_unless](#policies-bypass-forbid_unless) - -### Examples - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `condition` - arg 1 | ``any`` | A check or list of checks that must be true in order for this policy to apply. | -| `description` | `String.t` | A description for the policy, used when explaining authorization results | -| `access_type` | `:strict \| :filter \| :runtime` | What portion of the checks inside the policy are allowed to run. See the guide for more. | - - -## policies.bypass.authorize_if - -```elixir -authorize_if check -``` - ---- - -Introspection Target: `Ash.Policy.Check` - -If the check is true, the request is authorized, otherwise run remaining checks. - ---- - - - -### Examples -``` -authorize_if logged_in() -``` - - -``` -authorize_if actor_attribute_matches_record(:group, :group) -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `check` - required-arg 1 | ``any`` | The check to run. See `Ash.Policy.Check` for more. | -| `name` | `String.t` | A short name or description for the check, used when explaining authorization results | - - - - -## policies.bypass.forbid_if - -```elixir -forbid_if check -``` - ---- - -Introspection Target: `Ash.Policy.Check` - -If the check is true, the request is forbidden, otherwise run remaining checks. - ---- - - - -### Examples -``` -forbid_if not_logged_in() -``` - - -``` -forbid_if actor_attribute_matches_record(:group, :blacklisted_groups) -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `check` - required-arg 1 | ``any`` | The check to run. See `Ash.Policy.Check` for more. | -| `name` | `String.t` | A short name or description for the check, used when explaining authorization results | - - - - -## policies.bypass.authorize_unless - -```elixir -authorize_unless check -``` - ---- - -Introspection Target: `Ash.Policy.Check` - -If the check is false, the request is authorized, otherwise run remaining checks. - ---- - - - -### Examples -``` -authorize_unless not_logged_in() -``` - - -``` -authorize_unless actor_attribute_matches_record(:group, :blacklisted_groups) -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `check` - required-arg 1 | ``any`` | The check to run. See `Ash.Policy.Check` for more. | -| `name` | `String.t` | A short name or description for the check, used when explaining authorization results | - - - - -## policies.bypass.forbid_unless - -```elixir -forbid_unless check -``` - ---- - -Introspection Target: `Ash.Policy.Check` - -If the check is true, the request is forbidden, otherwise run remaining checks. - ---- - - - -### Examples -``` -forbid_unless logged_in() -``` - - -``` -forbid_unless actor_attribute_matches_record(:group, :group) -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `check` - required-arg 1 | ``any`` | The check to run. See `Ash.Policy.Check` for more. | -| `name` | `String.t` | A short name or description for the check, used when explaining authorization results | - - - - - - - - - -## field_policies - ---- - - * [field_policy_bypass](#field_policies-field_policy_bypass) - * authorize_if - * forbid_if - * authorize_unless - * forbid_unless - * [field_policy](#field_policies-field_policy) - * authorize_if - * forbid_if - * authorize_unless - * forbid_unless - -### Examples -``` -field_policies do - field_policy :admin_only_field do - authorize_if actor_attribute_equals(:admin, true) - end -end - -``` - - -``` -# Example of denylist style -field_policies do - field_policy [:sensitive, :fields] do - authorize_if actor_attribute_equals(:admin, true) - end - - field_policy :* do - authorize_if always() - end -end - -``` - - - -## field_policies.field_policy_bypass - -```elixir -field_policy_bypass fields, condition \ {Ash.Policy.Check.Static, [result: true]} -``` - ---- - -Introspection Target: `Ash.Policy.FieldPolicy` - -A field policy that, if passed, will skip all following field policies for that field or fields. If failed, field authorization moves on to the next policy - ---- - - * [authorize_if](#field_policies-field_policy_bypass-authorize_if) - * [forbid_if](#field_policies-field_policy_bypass-forbid_if) - * [authorize_unless](#field_policies-field_policy_bypass-authorize_unless) - * [forbid_unless](#field_policies-field_policy_bypass-forbid_unless) - -### Examples - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `fields` - arg 1 | `list(atom) \| atom` | The field or fields that the policy applies to. | -| `condition` - arg 2 | ``any`` | A check or list of checks that must be true in order for this field policy to apply. If not specified, it always applies. | -| `description` | `String.t` | A description for the policy, used when explaining authorization results | - - -## field_policies.field_policy_bypass.authorize_if - -```elixir -authorize_if check -``` - ---- - -Introspection Target: `Ash.Policy.Check` - -If the check is true, the request is authorized, otherwise run remaining checks. - ---- - - - -### Examples -``` -authorize_if logged_in() -``` - - -``` -authorize_if actor_attribute_matches_record(:group, :group) -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `check` - required-arg 1 | ``any`` | The check to run. See `Ash.Policy.Check` for more. | -| `name` | `String.t` | A short name or description for the check, used when explaining authorization results | - - - - -## field_policies.field_policy_bypass.forbid_if - -```elixir -forbid_if check -``` - ---- - -Introspection Target: `Ash.Policy.Check` - -If the check is true, the request is forbidden, otherwise run remaining checks. - ---- - - - -### Examples -``` -forbid_if not_logged_in() -``` - - -``` -forbid_if actor_attribute_matches_record(:group, :blacklisted_groups) -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `check` - required-arg 1 | ``any`` | The check to run. See `Ash.Policy.Check` for more. | -| `name` | `String.t` | A short name or description for the check, used when explaining authorization results | - - - - -## field_policies.field_policy_bypass.authorize_unless - -```elixir -authorize_unless check -``` - ---- - -Introspection Target: `Ash.Policy.Check` - -If the check is false, the request is authorized, otherwise run remaining checks. - ---- - - - -### Examples -``` -authorize_unless not_logged_in() -``` - - -``` -authorize_unless actor_attribute_matches_record(:group, :blacklisted_groups) -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `check` - required-arg 1 | ``any`` | The check to run. See `Ash.Policy.Check` for more. | -| `name` | `String.t` | A short name or description for the check, used when explaining authorization results | - - - - -## field_policies.field_policy_bypass.forbid_unless - -```elixir -forbid_unless check -``` - ---- - -Introspection Target: `Ash.Policy.Check` - -If the check is true, the request is forbidden, otherwise run remaining checks. - ---- - - - -### Examples -``` -forbid_unless logged_in() -``` - - -``` -forbid_unless actor_attribute_matches_record(:group, :group) -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `check` - required-arg 1 | ``any`` | The check to run. See `Ash.Policy.Check` for more. | -| `name` | `String.t` | A short name or description for the check, used when explaining authorization results | - - - - - - -## field_policies.field_policy - -```elixir -field_policy fields, condition \ {Ash.Policy.Check.Static, [result: true]} -``` - ---- - -Introspection Target: `Ash.Policy.FieldPolicy` - -Field policies behave similarly to policies. See `d:Ash.Policy.Authorizer.field_policies` -for more. - - ---- - - * [authorize_if](#field_policies-field_policy-authorize_if) - * [forbid_if](#field_policies-field_policy-forbid_if) - * [authorize_unless](#field_policies-field_policy-authorize_unless) - * [forbid_unless](#field_policies-field_policy-forbid_unless) - -### Examples - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `fields` - arg 1 | `list(atom) \| atom` | The field or fields that the policy applies to. | -| `condition` - arg 2 | ``any`` | A check or list of checks that must be true in order for this field policy to apply. If not specified, it always applies. | -| `description` | `String.t` | A description for the policy, used when explaining authorization results | - - -## field_policies.field_policy.authorize_if - -```elixir -authorize_if check -``` - ---- - -Introspection Target: `Ash.Policy.Check` - -If the check is true, the request is authorized, otherwise run remaining checks. - ---- - - - -### Examples -``` -authorize_if logged_in() -``` - - -``` -authorize_if actor_attribute_matches_record(:group, :group) -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `check` - required-arg 1 | ``any`` | The check to run. See `Ash.Policy.Check` for more. | -| `name` | `String.t` | A short name or description for the check, used when explaining authorization results | - - - - -## field_policies.field_policy.forbid_if - -```elixir -forbid_if check -``` - ---- - -Introspection Target: `Ash.Policy.Check` - -If the check is true, the request is forbidden, otherwise run remaining checks. - ---- - - - -### Examples -``` -forbid_if not_logged_in() -``` - - -``` -forbid_if actor_attribute_matches_record(:group, :blacklisted_groups) -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `check` - required-arg 1 | ``any`` | The check to run. See `Ash.Policy.Check` for more. | -| `name` | `String.t` | A short name or description for the check, used when explaining authorization results | - - - - -## field_policies.field_policy.authorize_unless - -```elixir -authorize_unless check -``` - ---- - -Introspection Target: `Ash.Policy.Check` - -If the check is false, the request is authorized, otherwise run remaining checks. - ---- - - - -### Examples -``` -authorize_unless not_logged_in() -``` - - -``` -authorize_unless actor_attribute_matches_record(:group, :blacklisted_groups) -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `check` - required-arg 1 | ``any`` | The check to run. See `Ash.Policy.Check` for more. | -| `name` | `String.t` | A short name or description for the check, used when explaining authorization results | - - - - -## field_policies.field_policy.forbid_unless - -```elixir -forbid_unless check -``` - ---- - -Introspection Target: `Ash.Policy.Check` - -If the check is true, the request is forbidden, otherwise run remaining checks. - ---- - - - -### Examples -``` -forbid_unless logged_in() -``` - - -``` -forbid_unless actor_attribute_matches_record(:group, :group) -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `check` - required-arg 1 | ``any`` | The check to run. See `Ash.Policy.Check` for more. | -| `name` | `String.t` | A short name or description for the check, used when explaining authorization results | - - - - - - - - - diff --git a/documentation/dsls/DSL:-Ash.Registry.cheatmd b/documentation/dsls/DSL:-Ash.Registry.cheatmd deleted file mode 100644 index 557f0cfd..00000000 --- a/documentation/dsls/DSL:-Ash.Registry.cheatmd +++ /dev/null @@ -1,65 +0,0 @@ -# DSL: Ash.Registry.Dsl - -A small DSL for declaring an `Ash.Registry`. Not generally necessary any longer. - -`Ash.Registry` can be used generically, but the main way it is used in Ash is to provide a compile-time registry for an Ash Api. - - -## entries -List the entries present in this registry - ---- - - * [entry](#entries-entry) - -### Examples -``` -entries do - entry MyApp.User - entry MyApp.Post - entry MyApp.Comment -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `warn_on_empty?` | `boolean` | true | Set to `false` to ignore warnings about an empty registry | - - - -## entries.entry - -```elixir -entry entry -``` - ---- - -Introspection Target: `Ash.Registry.Entry` - -A reference to an ash module (typically a resource) - ---- - - - -### Examples -``` -entry MyApp.User -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `entry` - required-arg 1 | `atom` | The referenced module | - - - - - - - diff --git a/documentation/dsls/DSL:-Ash.Resource.cheatmd b/documentation/dsls/DSL:-Ash.Resource.cheatmd deleted file mode 100644 index a133d8d2..00000000 --- a/documentation/dsls/DSL:-Ash.Resource.cheatmd +++ /dev/null @@ -1,2627 +0,0 @@ -# DSL: Ash.Resource.Dsl - - - -## attributes - ---- - - * [attribute](#attributes-attribute) - * [create_timestamp](#attributes-create_timestamp) - * [update_timestamp](#attributes-update_timestamp) - * [integer_primary_key](#attributes-integer_primary_key) - * [uuid_primary_key](#attributes-uuid_primary_key) - -### Examples -``` -attributes do - uuid_primary_key :id - - attribute :first_name, :string do - allow_nil? false - end - - attribute :last_name, :string do - allow_nil? false - end - - attribute :email, :string do - allow_nil? false - - constraints [ - match: ~r/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$/ - ] - end - - attribute :type, :atom do - constraints [ - one_of: [:admin, :teacher, :student] - ] - end - - create_timestamp :inserted_at - update_timestamp :updated_at -end - -``` - - - -## attributes.attribute - -```elixir -attribute name, type -``` - ---- - -Introspection Target: `Ash.Resource.Attribute` - -Declares an attribute on the resource. - - ---- - - - -### Examples -``` -attribute :name, :string do - allow_nil? false -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the attribute. | -| `type` - required-arg 2 | `module` | | The type of the attribute. See `Ash.Type` for more. | -| `constraints` | `Keyword.t` | | Constraints to provide to the type when casting the value. For more, see the [constraints topic](/documentation/topics/constraints.md). | -| `description` | `String.t` | | An optional description for the attribute. | -| `sensitive?` | `boolean` | false | Whether or not the attribute value contains sensitive information, like PII. See the [Security guide](/documentation/topics/security.md) for more. | -| `source` | `atom` | | If the field should be mapped to a different name in the data layer. Support varies by data layer. | -| `always_select?` | `boolean` | false | Whether or not to ensure this attribute is always selected when reading from the database, regardless of applied select statements. | -| `primary_key?` | `boolean` | false | Whether the attribute is the primary key. Composite primary key is also possible by using `primary_key? true` in more than one attribute. If primary_key? is true, allow_nil? must be false. | -| `allow_nil?` | `boolean` | true | Whether or not the attribute can be set to nil. If nil value is given error is raised. | -| `generated?` | `boolean` | false | Whether or not the value may be generated by the data layer. | -| `writable?` | `boolean` | true | Whether or not the value can be written to. Non-writable attributes can still be written with `Ash.Changeset.force_change_attribute/3`. | -| `private?` | `boolean` | false | The attribute is not publically writable, and should not be exposed over any public interfaces. See the [security guide](/documentation/topics/security.md) for more. | -| `default` | `(-> any) \| mfa \| any()` | | A value to be set on all creates, unless a value is being provided already. | -| `update_default` | `(-> any) \| mfa \| any()` | | A value to be set on all updates, unless a value is being provided already. | -| `filterable?` | `boolean \| :simple_equality` | true | Whether or not the attribute can be referenced in filters. | -| `match_other_defaults?` | `boolean` | false | Ensures that other attributes that use the same "lazy" default (a function or an mfa), use the same default value. Has no effect unless `default` is a zero argument function. | - - - - -## attributes.create_timestamp - -```elixir -create_timestamp name -``` - ---- - -Introspection Target: `Ash.Resource.Attribute` - -Declares a non-writable attribute with a create default of `&DateTime.utc_now/0` - -Accepts all the same options as `d:Ash.Resource.Dsl.attributes.attribute`, except it sets -the following different defaults: - - writable? false - private? true - default &DateTime.utc_now/0 - match_other_defaults? true - type Ash.Type.UTCDatetimeUsec - allow_nil? false - - ---- - - - -### Examples -``` -create_timestamp :inserted_at -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the attribute. | -| `type` | `module` | Ash.Type.UtcDatetimeUsec | The type of the attribute. See `Ash.Type` for more. | -| `constraints` | `Keyword.t` | | Constraints to provide to the type when casting the value. For more, see the [constraints topic](/documentation/topics/constraints.md). | -| `description` | `String.t` | | An optional description for the attribute. | -| `sensitive?` | `boolean` | false | Whether or not the attribute value contains sensitive information, like PII. See the [Security guide](/documentation/topics/security.md) for more. | -| `source` | `atom` | | If the field should be mapped to a different name in the data layer. Support varies by data layer. | -| `always_select?` | `boolean` | false | Whether or not to ensure this attribute is always selected when reading from the database, regardless of applied select statements. | -| `primary_key?` | `boolean` | false | Whether the attribute is the primary key. Composite primary key is also possible by using `primary_key? true` in more than one attribute. If primary_key? is true, allow_nil? must be false. | -| `allow_nil?` | `boolean` | false | Whether or not the attribute can be set to nil. If nil value is given error is raised. | -| `generated?` | `boolean` | false | Whether or not the value may be generated by the data layer. | -| `writable?` | `boolean` | false | Whether or not the value can be written to. Non-writable attributes can still be written with `Ash.Changeset.force_change_attribute/3`. | -| `private?` | `boolean` | true | The attribute is not publically writable, and should not be exposed over any public interfaces. See the [security guide](/documentation/topics/security.md) for more. | -| `default` | `(-> any) \| mfa \| any()` | &DateTime.utc_now/0 | A value to be set on all creates, unless a value is being provided already. | -| `update_default` | `(-> any) \| mfa \| any()` | | A value to be set on all updates, unless a value is being provided already. | -| `filterable?` | `boolean \| :simple_equality` | true | Whether or not the attribute can be referenced in filters. | -| `match_other_defaults?` | `boolean` | true | Ensures that other attributes that use the same "lazy" default (a function or an mfa), use the same default value. Has no effect unless `default` is a zero argument function. | - - - - -## attributes.update_timestamp - -```elixir -update_timestamp name -``` - ---- - -Introspection Target: `Ash.Resource.Attribute` - -Declares a non-writable attribute with a create and update default of `&DateTime.utc_now/0` - -Accepts all the same options as `d:Ash.Resource.Dsl.attributes.attribute`, except it sets -the following different defaults: - - writable? false - private? true - default &DateTime.utc_now/0 - match_other_defaults? true - update_default &DateTime.utc_now/0 - type Ash.Type.UTCDatetimeUsec - allow_nil? false - - ---- - - - -### Examples -``` -update_timestamp :inserted_at -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the attribute. | -| `type` | `module` | Ash.Type.UtcDatetimeUsec | The type of the attribute. See `Ash.Type` for more. | -| `constraints` | `Keyword.t` | | Constraints to provide to the type when casting the value. For more, see the [constraints topic](/documentation/topics/constraints.md). | -| `description` | `String.t` | | An optional description for the attribute. | -| `sensitive?` | `boolean` | false | Whether or not the attribute value contains sensitive information, like PII. See the [Security guide](/documentation/topics/security.md) for more. | -| `source` | `atom` | | If the field should be mapped to a different name in the data layer. Support varies by data layer. | -| `always_select?` | `boolean` | false | Whether or not to ensure this attribute is always selected when reading from the database, regardless of applied select statements. | -| `primary_key?` | `boolean` | false | Whether the attribute is the primary key. Composite primary key is also possible by using `primary_key? true` in more than one attribute. If primary_key? is true, allow_nil? must be false. | -| `allow_nil?` | `boolean` | false | Whether or not the attribute can be set to nil. If nil value is given error is raised. | -| `generated?` | `boolean` | false | Whether or not the value may be generated by the data layer. | -| `writable?` | `boolean` | false | Whether or not the value can be written to. Non-writable attributes can still be written with `Ash.Changeset.force_change_attribute/3`. | -| `private?` | `boolean` | true | The attribute is not publically writable, and should not be exposed over any public interfaces. See the [security guide](/documentation/topics/security.md) for more. | -| `default` | `(-> any) \| mfa \| any()` | &DateTime.utc_now/0 | A value to be set on all creates, unless a value is being provided already. | -| `update_default` | `(-> any) \| mfa \| any()` | &DateTime.utc_now/0 | A value to be set on all updates, unless a value is being provided already. | -| `filterable?` | `boolean \| :simple_equality` | true | Whether or not the attribute can be referenced in filters. | -| `match_other_defaults?` | `boolean` | true | Ensures that other attributes that use the same "lazy" default (a function or an mfa), use the same default value. Has no effect unless `default` is a zero argument function. | - - - - -## attributes.integer_primary_key - -```elixir -integer_primary_key name -``` - ---- - -Introspection Target: `Ash.Resource.Attribute` - -Declares a generated, non writable, non-nil, primary key column of type integer. - -Generated integer primary keys must be supported by the data layer. - -Accepts all the same options as `d:Ash.Resource.Dsl.attributes.attribute`, except for `allow_nil?`, but it sets -the following different defaults: - - writable? false - primary_key? true - generated? true - type :integer - - ---- - - - -### Examples -``` -integer_primary_key :id -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the attribute. | -| `type` | `module` | :integer | The type of the attribute. See `Ash.Type` for more. | -| `constraints` | `Keyword.t` | | Constraints to provide to the type when casting the value. For more, see the [constraints topic](/documentation/topics/constraints.md). | -| `description` | `String.t` | | An optional description for the attribute. | -| `sensitive?` | `boolean` | false | Whether or not the attribute value contains sensitive information, like PII. See the [Security guide](/documentation/topics/security.md) for more. | -| `source` | `atom` | | If the field should be mapped to a different name in the data layer. Support varies by data layer. | -| `always_select?` | `boolean` | false | Whether or not to ensure this attribute is always selected when reading from the database, regardless of applied select statements. | -| `primary_key?` | `boolean` | true | Whether the attribute is the primary key. Composite primary key is also possible by using `primary_key? true` in more than one attribute. If primary_key? is true, allow_nil? must be false. | -| `generated?` | `boolean` | true | Whether or not the value may be generated by the data layer. | -| `writable?` | `boolean` | false | Whether or not the value can be written to. Non-writable attributes can still be written with `Ash.Changeset.force_change_attribute/3`. | -| `private?` | `boolean` | false | The attribute is not publically writable, and should not be exposed over any public interfaces. See the [security guide](/documentation/topics/security.md) for more. | -| `default` | `(-> any) \| mfa \| any()` | | A value to be set on all creates, unless a value is being provided already. | -| `update_default` | `(-> any) \| mfa \| any()` | | A value to be set on all updates, unless a value is being provided already. | -| `filterable?` | `boolean \| :simple_equality` | true | Whether or not the attribute can be referenced in filters. | -| `match_other_defaults?` | `boolean` | false | Ensures that other attributes that use the same "lazy" default (a function or an mfa), use the same default value. Has no effect unless `default` is a zero argument function. | - - - - -## attributes.uuid_primary_key - -```elixir -uuid_primary_key name -``` - ---- - -Introspection Target: `Ash.Resource.Attribute` - -Declares a non writable, non-nil, primary key column of type `uuid`, which defaults to `Ash.UUID.generate/0`. - -Accepts all the same options as `d:Ash.Resource.Dsl.attributes.attribute`, except for `allow_nil?`, but it sets -the following different defaults: - - writable? false - default &Ash.UUID.generate/0 - primary_key? true - generated? true - type :uuid - - ---- - - - -### Examples -``` -uuid_primary_key :id -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the attribute. | -| `type` | `module` | :uuid | The type of the attribute. See `Ash.Type` for more. | -| `constraints` | `Keyword.t` | | Constraints to provide to the type when casting the value. For more, see the [constraints topic](/documentation/topics/constraints.md). | -| `description` | `String.t` | | An optional description for the attribute. | -| `sensitive?` | `boolean` | false | Whether or not the attribute value contains sensitive information, like PII. See the [Security guide](/documentation/topics/security.md) for more. | -| `source` | `atom` | | If the field should be mapped to a different name in the data layer. Support varies by data layer. | -| `always_select?` | `boolean` | false | Whether or not to ensure this attribute is always selected when reading from the database, regardless of applied select statements. | -| `primary_key?` | `boolean` | true | Whether the attribute is the primary key. Composite primary key is also possible by using `primary_key? true` in more than one attribute. If primary_key? is true, allow_nil? must be false. | -| `generated?` | `boolean` | false | Whether or not the value may be generated by the data layer. | -| `writable?` | `boolean` | false | Whether or not the value can be written to. Non-writable attributes can still be written with `Ash.Changeset.force_change_attribute/3`. | -| `private?` | `boolean` | false | The attribute is not publically writable, and should not be exposed over any public interfaces. See the [security guide](/documentation/topics/security.md) for more. | -| `default` | `(-> any) \| mfa \| any()` | &Ash.UUID.generate/0 | A value to be set on all creates, unless a value is being provided already. | -| `update_default` | `(-> any) \| mfa \| any()` | | A value to be set on all updates, unless a value is being provided already. | -| `filterable?` | `boolean \| :simple_equality` | true | Whether or not the attribute can be referenced in filters. | -| `match_other_defaults?` | `boolean` | false | Ensures that other attributes that use the same "lazy" default (a function or an mfa), use the same default value. Has no effect unless `default` is a zero argument function. | - - - - - - - -## relationships - ---- - - * [has_one](#relationships-has_one) - * [has_many](#relationships-has_many) - * [many_to_many](#relationships-many_to_many) - * [belongs_to](#relationships-belongs_to) - -### Examples -``` -relationships do - belongs_to :post, MyApp.Post do - primary_key? true - end - - belongs_to :category, MyApp.Category do - primary_key? true - end -end - -``` - - -``` -relationships do - belongs_to :author, MyApp.Author - - many_to_many :categories, MyApp.Category do - through MyApp.PostCategory - destination_attribute_on_join_resource :category_id - source_attribute_on_join_resource :post_id - end -end - -``` - - -``` -relationships do - has_many :posts, MyApp.Post do - destination_attribute :author_id - end - - has_many :composite_key_posts, MyApp.CompositeKeyPost do - destination_attribute :author_id - end -end - -``` - - - -## relationships.has_one - -```elixir -has_one name, destination -``` - ---- - -Introspection Target: `Ash.Resource.Relationships.HasOne` - -Declares a `has_one` relationship. In a relational database, the foreign key would be on the *other* table. - -Generally speaking, a `has_one` also implies that the destination table is unique on that foreign key. - -See the [relationships guide](/documentation/topics/relationships.md) for more. - - ---- - - - -### Examples -``` -# In a resource called `Word` -has_one :dictionary_entry, DictionaryEntry do - source_attribute :text - destination_attribute :word_text -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - arg 1 | `atom` | | The name of the relationship | -| `destination` - arg 2 | `module` | | The destination resource | -| `manual` | `(any, any -> any) \| module` | | A module that implements `Ash.Resource.ManualRelationship`. Also accepts a 2 argument function that takes the source records and the context. | -| `no_attributes?` | `boolean` | | All existing entities are considered related, i.e this relationship is not based on any fields, and `source_attribute` and `destination_attribute` are ignored. See the See the [relationships guide](/documentation/topics/relationships.md) for more. | -| `allow_nil?` | `boolean` | true | Marks the relationship as required. Has no effect on validations, but can inform extensions that there will always be a related entity. | -| `from_many?` | `boolean` | false | Signal that this relationship is actually a `has_many` where the first record is given via the `sort`. This will allow data layers to properly deduplicate when necessary. | -| `description` | `String.t` | | An optional description for the relationship | -| `destination_attribute` | `atom` | | The attribute on the related resource that should match the `source_attribute` configured on this resource. | -| `validate_destination_attribute?` | `boolean` | true | Whether or not to validate that the destination field exists on the destination resource | -| `source_attribute` | `atom` | :id | The field on this resource that should match the `destination_attribute` on the related resource. | -| `relationship_context` | ``any`` | | Context to be set on any queries or changesets generated for managing or querying this relationship. | -| `private?` | `boolean` | false | Whether or not the relationship will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql See the [security guide](/documentation/topics/security.md) for more. | -| `not_found_message` | `String.t` | | A message to show if there is a conflict with this relationship in the database on update or create, or when managing relationships. | -| `writable?` | `boolean` | true | Whether or not the relationship may be managed. | -| `read_action` | `atom` | | The read action on the destination resource to use when loading data and filtering. | -| `api` | `atom` | | The API module to use when working with the related entity. | -| `filter` | ``any`` | | A filter to be applied when reading the relationship. | -| `filterable?` | `boolean` | true | If set to `false`, the relationship will not be usable in filters. | -| `sort` | ``any`` | | A sort statement to be applied when loading the relationship. | -| `could_be_related_at_creation?` | `boolean` | false | Whether or not related values may exist for this relationship at creation. | -| `violation_message` | `String.t` | | A message to show if there is a conflict with this relationship in the database on destroy. | - - - - -## relationships.has_many - -```elixir -has_many name, destination -``` - ---- - -Introspection Target: `Ash.Resource.Relationships.HasMany` - -Declares a `has_many` relationship. There can be any number of related entities. - -See the [relationships guide](/documentation/topics/relationships.md) for more. - - ---- - - - -### Examples -``` -# In a resource called `Word` -has_many :definitions, DictionaryDefinition do - source_attribute :text - destination_attribute :word_text -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - arg 1 | `atom` | | The name of the relationship | -| `destination` - arg 2 | `module` | | The destination resource | -| `manual` | `(any, any -> any) \| module` | | A module that implements `Ash.Resource.ManualRelationship`. Also accepts a 2 argument function that takes the source records and the context. | -| `no_attributes?` | `boolean` | | All existing entities are considered related, i.e this relationship is not based on any fields, and `source_attribute` and `destination_attribute` are ignored. See the See the [relationships guide](/documentation/topics/relationships.md) for more. | -| `description` | `String.t` | | An optional description for the relationship | -| `destination_attribute` | `atom` | | The attribute on the related resource that should match the `source_attribute` configured on this resource. | -| `validate_destination_attribute?` | `boolean` | true | Whether or not to validate that the destination field exists on the destination resource | -| `source_attribute` | `atom` | :id | The field on this resource that should match the `destination_attribute` on the related resource. | -| `relationship_context` | ``any`` | | Context to be set on any queries or changesets generated for managing or querying this relationship. | -| `private?` | `boolean` | false | Whether or not the relationship will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql See the [security guide](/documentation/topics/security.md) for more. | -| `not_found_message` | `String.t` | | A message to show if there is a conflict with this relationship in the database on update or create, or when managing relationships. | -| `writable?` | `boolean` | true | Whether or not the relationship may be managed. | -| `read_action` | `atom` | | The read action on the destination resource to use when loading data and filtering. | -| `api` | `atom` | | The API module to use when working with the related entity. | -| `filter` | ``any`` | | A filter to be applied when reading the relationship. | -| `filterable?` | `boolean` | true | If set to `false`, the relationship will not be usable in filters. | -| `sort` | ``any`` | | A sort statement to be applied when loading the relationship. | -| `could_be_related_at_creation?` | `boolean` | false | Whether or not related values may exist for this relationship at creation. | -| `violation_message` | `String.t` | | A message to show if there is a conflict with this relationship in the database on destroy. | - - - - -## relationships.many_to_many - -```elixir -many_to_many name, destination -``` - ---- - -Introspection Target: `Ash.Resource.Relationships.ManyToMany` - -Declares a `many_to_many` relationship. Many to many relationships require a join resource. - -A join resource is a resource that consists of a relationship to the source and destination of the many to many. - -See the [relationships guide](/documentation/topics/relationships.md) for more. - - ---- - - - -### Examples -``` -# In a resource called `Word` -many_to_many :books, Book do - through BookWord - source_attribute :text - source_attribute_on_join_resource :word_text - destination_attribute :id - destination_attribute_on_join_resource :book_id -end - -# And in `BookWord` (the join resource) -belongs_to :book, Book, primary_key?: true, allow_nil?: false -belongs_to :word, Word, primary_key?: true, allow_nil?: false - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - arg 1 | `atom` | | The name of the relationship | -| `destination` - arg 2 | `module` | | The destination resource | -| `source_attribute_on_join_resource` - required | `atom` | | The attribute on the join resource that should line up with `source_attribute` on this resource. | -| `destination_attribute_on_join_resource` - required | `atom` | | The attribute on the join resource that should line up with `destination_attribute` on the related resource. | -| `through` - required | `module` | | The resource to use as the join resource. | -| `join_relationship` | `atom` | | The has_many relationship to the join resource. Defaults to _join_assoc | -| `description` | `String.t` | | An optional description for the relationship | -| `destination_attribute` | `atom` | :id | The attribute on the related resource that should match the `source_attribute` configured on this resource. | -| `validate_destination_attribute?` | `boolean` | true | Whether or not to validate that the destination field exists on the destination resource | -| `source_attribute` | `atom` | :id | The field on this resource that should match the `destination_attribute` on the related resource. | -| `relationship_context` | ``any`` | | Context to be set on any queries or changesets generated for managing or querying this relationship. | -| `private?` | `boolean` | false | Whether or not the relationship will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql See the [security guide](/documentation/topics/security.md) for more. | -| `not_found_message` | `String.t` | | A message to show if there is a conflict with this relationship in the database on update or create, or when managing relationships. | -| `writable?` | `boolean` | true | Whether or not the relationship may be managed. | -| `read_action` | `atom` | | The read action on the destination resource to use when loading data and filtering. | -| `api` | `atom` | | The API module to use when working with the related entity. | -| `filter` | ``any`` | | A filter to be applied when reading the relationship. | -| `filterable?` | `boolean` | true | If set to `false`, the relationship will not be usable in filters. | -| `sort` | ``any`` | | A sort statement to be applied when loading the relationship. | -| `could_be_related_at_creation?` | `boolean` | false | Whether or not related values may exist for this relationship at creation. | -| `violation_message` | `String.t` | | A message to show if there is a conflict with this relationship in the database on destroy. | - - - - -## relationships.belongs_to - -```elixir -belongs_to name, destination -``` - ---- - -Introspection Target: `Ash.Resource.Relationships.BelongsTo` - -Declares a `belongs_to` relationship. In a relational database, the foreign key would be on the *source* table. - -This creates a field on the resource with the corresponding name and type, unless `define_attribute?: false` is provided. - -See the [relationships guide](/documentation/topics/relationships.md) for more. - - ---- - - - -### Examples -``` -# In a resource called `Word` -belongs_to :dictionary_entry, DictionaryEntry do - source_attribute :text, - destination_attribute :word_text -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - arg 1 | `atom` | | The name of the relationship | -| `destination` - arg 2 | `module` | | The destination resource | -| `primary_key?` | `boolean` | false | Whether the generated attribute is, or is part of, the primary key of a resource. | -| `allow_nil?` | `boolean` | true | Whether this relationship must always be present, e.g: must be included on creation, and never removed (it may be modified). The generated attribute will not allow nil values. | -| `attribute_writable?` | `boolean` | false | Whether the generated attribute will be marked as public & writable. | -| `define_attribute?` | `boolean` | true | If set to `false` an attribute is not created on the resource for this relationship, and one must be manually added in `attributes`, invalidating many other options. | -| `attribute_type` | ``any`` | :uuid | The type of the generated created attribute. See `Ash.Type` for more. | -| `description` | `String.t` | | An optional description for the relationship | -| `destination_attribute` | `atom` | :id | The attribute on the related resource that should match the `source_attribute` configured on this resource. | -| `validate_destination_attribute?` | `boolean` | true | Whether or not to validate that the destination field exists on the destination resource | -| `source_attribute` | `atom` | | The field on this resource that should match the `destination_attribute` on the related resource. - Defaults to _id | -| `relationship_context` | ``any`` | | Context to be set on any queries or changesets generated for managing or querying this relationship. | -| `private?` | `boolean` | false | Whether or not the relationship will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql See the [security guide](/documentation/topics/security.md) for more. | -| `not_found_message` | `String.t` | | A message to show if there is a conflict with this relationship in the database on update or create, or when managing relationships. | -| `writable?` | `boolean` | true | Whether or not the relationship may be managed. | -| `read_action` | `atom` | | The read action on the destination resource to use when loading data and filtering. | -| `api` | `atom` | | The API module to use when working with the related entity. | -| `filter` | ``any`` | | A filter to be applied when reading the relationship. | -| `filterable?` | `boolean` | true | If set to `false`, the relationship will not be usable in filters. | -| `sort` | ``any`` | | A sort statement to be applied when loading the relationship. | -| `violation_message` | `String.t` | | A message to show if there is a conflict with this relationship in the database on destroy. | - - - - - - - -## actions -A section for declaring resource actions. - -All manipulation of data through the underlying data layer happens through actions. -There are four types of action: `create`, `read`, `update`, and `destroy`. You may -recognize these from the acronym `CRUD`. You can have multiple actions of the same -type, as long as they have different names. This is the primary mechanism for customizing -your resources to conform to your business logic. It is normal and expected to have -multiple actions of each type in a large application. - - ---- - - * [action](#actions-action) - * argument - * [create](#actions-create) - * change - * validate - * argument - * metadata - * [read](#actions-read) - * argument - * prepare - * pagination - * metadata - * [update](#actions-update) - * change - * validate - * metadata - * argument - * [destroy](#actions-destroy) - * change - * validate - * metadata - * argument - -### Examples -``` -actions do - create :signup do - argument :password, :string - argument :password_confirmation, :string - validate confirm(:password, :password_confirmation) - change {MyApp.HashPassword, []} # A custom implemented Change - end - - read :me do - # An action that auto filters to only return the user for the current user - filter [id: actor(:id)] - end - - update :update do - accept [:first_name, :last_name] - end - - destroy do - change set_attribute(:deleted_at, &DateTime.utc_now/0) - # This tells it that even though this is a delete action, it - # should be treated like an update because `deleted_at` is set. - # This should be coupled with a `base_filter` on the resource - # or with the read actions having a `filter` for `is_nil: :deleted_at` - soft? true - end -end - -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `defaults` | `list(:create \| :read \| :update \| :destroy)` | Creates a simple action of each specified type, with the same name as the type. These will be `primary?` unless one already exists for that type. Embedded resources, however, have a default of all resource types. | -| `default_accept` | `list(atom)` | A default value for the `accept` option for each action. Defaults to all public attributes. | - - - -## actions.action - -```elixir -action name, returns -``` - ---- - -Introspection Target: `Ash.Resource.Actions.Action` - -Declares a generic action. A combination of arguments, a return type and a run function. - -For calling this action, see the `Ash.Api` documentation. - - ---- - - * [argument](#actions-action-argument) - -### Examples -``` -action :top_user_emails, {:array, :string} do - argument :limit, :integer, default: 10, allow_nil?: false - run fn input, context -> - with {:ok, top_users} <- top_users(input.limit) do - {:ok, Enum.map(top_users, &(&1.email))} - end - end -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the action | -| `returns` - arg 2 | `module` | | The return type of the action. See `Ash.Type` for more. | -| `constraints` | `Keyword.t` | | Constraints for the return type. See the [constriants topic](/documentation/topics/constraints.md) for more. | -| `run` | `(any, any -> any) \| module` | | | -| `primary?` | `boolean` | false | Whether or not this action should be used when no action is specified by the caller. | -| `description` | `String.t` | | An optional description for the action | -| `transaction?` | `boolean` | | Whether or not the action should be run in transactions. Reads default to false, while create/update/destroy actions default to `true`. | -| `touches_resources` | `list(atom)` | | A list of resources that the action may touch, used when building transactions. | - - -## actions.action.argument - -```elixir -argument name, type -``` - ---- - -Introspection Target: `Ash.Resource.Actions.Argument` - -Declares an argument on the action - - ---- - - - -### Examples -``` -argument :password_confirmation, :string -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the argument | -| `type` - required-arg 2 | `module` | | The type of the argument. See `Ash.Type` for more. | -| `description` | `String.t` | | An optional description for the argument. | -| `constraints` | `Keyword.t` | [] | Constraints to provide to the type when casting the value. For more information, see [the constraints topic](/documentation/topics/constraints.md). | -| `allow_nil?` | `boolean` | true | Whether or not the argument value may be nil (or may be not provided). If nil value is given error is raised. | -| `private?` | `boolean` | false | Whether or not the argument should be suppliable by the client. | -| `sensitive?` | `boolean` | false | Whether or not the argument value contains sensitive information, like PII. See the [security guide](/documentation/topics/security.md) for more. | -| `default` | ``any`` | | The default value for the argument to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value | - - - - - - -## actions.create - -```elixir -create name -``` - ---- - -Introspection Target: `Ash.Resource.Actions.Create` - -Declares a `create` action. For calling this action, see the `Ash.Api` documentation. - - ---- - - * [change](#actions-create-change) - * [validate](#actions-create-validate) - * [argument](#actions-create-argument) - * [metadata](#actions-create-metadata) - -### Examples -``` -create :register do - primary? true -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the action | -| `allow_nil_input` | `list(atom)` | | A list of attributes that would normally be required, but should not be for this action. They will still be validated just before the record is created. | -| `manual` | `(any, any -> any) \| module` | | Override the creation behavior. Accepts a module or module and opts, or a function that takes the changeset and context. See the [manual actions guide](/documentation/topics/manual-actions.md) for more. | -| `upsert?` | `boolean` | false | Forces all uses of this action to be treated as an upsert. | -| `upsert_identity` | `atom` | | The identity to use for the upsert. Cannot be overriden by the caller. Ignored if `upsert?` is not set to `true`. | -| `upsert_fields` | `list(atom)` | | The fields to overwrite in the case of an upsert. If not provided, all fields except for fields set by defaults will be overwritten. | -| `primary?` | `boolean` | false | Whether or not this action should be used when no action is specified by the caller. | -| `description` | `String.t` | | An optional description for the action | -| `transaction?` | `boolean` | | Whether or not the action should be run in transactions. Reads default to false, while create/update/destroy actions default to `true`. | -| `touches_resources` | `list(atom)` | | A list of resources that the action may touch, used when building transactions. | -| `accept` | `:all \| list(atom)` | | The list of attributes to accept. Defaults to all attributes on the resource | -| `delay_global_validations?` | `boolean` | false | If true, global validations will be done in a `before_action` hook, regardless of their configuration on the resource. | -| `skip_global_validations?` | `boolean` | false | If true, global validations will be skipped. Useful for manual actions. | -| `reject` | `:all \| list(atom)` | | A list of attributes not to accept. If this is specified along with `accept`, these are removed from the `accept` list. | -| `require_attributes` | `list(atom)` | | A list of attributes that would normally `allow_nil?`, to require for this action. No need to include attributes that already do not allow nil? | -| `error_handler` | `mfa` | | Sets the error handler on the changeset. See `Ash.Changeset.handle_errors/2` for more | -| `manual?` | `boolean` | | Instructs Ash to *skip* the actual update/create/destroy step at the data layer. See the [manual actions guide](/documentation/topics/manual-actions.md) for more. | - - -## actions.create.change - -```elixir -change change -``` - ---- - -Introspection Target: `Ash.Resource.Change` - -A change to be applied to the changeset. - -See `Ash.Resource.Change` for more. - - ---- - - - -### Examples -``` -change relate_actor(:reporter) -``` - - -``` -change {MyCustomChange, :foo} -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `change` - required-arg 1 | `(any, any -> any) \| module` | | The module and options for a change. Also accepts a function that takes the changeset and the context. See `Ash.Resource.Change.Builtins` for builtin changes. | -| `only_when_valid?` | `boolean` | false | If the change should only be run on valid changes. By default, all changes are run unless stated otherwise here. | -| `description` | `String.t` | | An optional description for the change | -| `where` | `list((any -> any) \| module)` | [] | Validations that should pass in order for this validation to apply. These validations failing will result in this validation being ignored. | - - - - -## actions.create.validate - -```elixir -validate validation -``` - ---- - -Introspection Target: `Ash.Resource.Validation` - -Declares a validation to be applied to the changeset. - -See `Ash.Resource.Validation` for more. - - ---- - - - -### Examples -``` -validate changing(:email) -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `validation` - required-arg 1 | `(any -> any) \| module` | | The module (or module and opts) that implements the `Ash.Resource.Validation` behaviour. Also accepts a one argument function that takes the changeset. | -| `where` | `(any -> any) \| module \| list((any -> any) \| module)` | [] | Validations that should pass in order for this validation to apply. Any of these validations failing will result in this validation being ignored. | -| `only_when_valid?` | `boolean` | false | If the validation should only run on valid changes. Useful for expensive validations or validations that depend on valid data. | -| `message` | `String.t` | | If provided, overrides any message set by the validation error | -| `description` | `String.t` | | An optional description for the validation | -| `before_action?` | `boolean` | false | If set to `true`, the validation will be run in a before_action hook | - - - - -## actions.create.argument - -```elixir -argument name, type -``` - ---- - -Introspection Target: `Ash.Resource.Actions.Argument` - -Declares an argument on the action - - ---- - - - -### Examples -``` -argument :password_confirmation, :string -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the argument | -| `type` - required-arg 2 | `module` | | The type of the argument. See `Ash.Type` for more. | -| `description` | `String.t` | | An optional description for the argument. | -| `constraints` | `Keyword.t` | [] | Constraints to provide to the type when casting the value. For more information, see [the constraints topic](/documentation/topics/constraints.md). | -| `allow_nil?` | `boolean` | true | Whether or not the argument value may be nil (or may be not provided). If nil value is given error is raised. | -| `private?` | `boolean` | false | Whether or not the argument should be suppliable by the client. | -| `sensitive?` | `boolean` | false | Whether or not the argument value contains sensitive information, like PII. See the [security guide](/documentation/topics/security.md) for more. | -| `default` | ``any`` | | The default value for the argument to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value | - - - - -## actions.create.metadata - -```elixir -metadata name, type -``` - ---- - -Introspection Target: `Ash.Resource.Actions.Metadata` - -A special kind of attribute that is only added to specific actions. Nothing sets this value, it must be set in a custom -change via `Ash.Resource.Info.put_metadata/3`. - - ---- - - - -### Examples -``` -metadata :api_token, :string, allow_nil?: false - -``` - - -``` -metadata :operation_id, :string, allow_nil?: false - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the metadata | -| `type` - required-arg 2 | ``any`` | | The type of the metadata. See `Ash.Type` for more. | -| `constraints` | `Keyword.t` | [] | Type constraints on the metadata | -| `description` | `String.t` | | An optional description for the metadata. | -| `allow_nil?` | `boolean` | true | Whether or not the metadata may return `nil` | -| `default` | ``any`` | | The default value for the metadata to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value | - - - - - - -## actions.read - -```elixir -read name -``` - ---- - -Introspection Target: `Ash.Resource.Actions.Read` - -Declares a `read` action. For calling this action, see the `Ash.Api` documentation. - - ---- - - * [argument](#actions-read-argument) - * [prepare](#actions-read-prepare) - * [pagination](#actions-read-pagination) - * [metadata](#actions-read-metadata) - -### Examples -``` -read :read_all do - primary? true -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the action | -| `filter` | ``any`` | | A filter template that will be applied whenever the action is used. See `Ash.Filter` for more on templates | -| `manual` | `(any, any, any -> any) \| module` | | Delegates running of the query to the provided module. Accepts a module or module and opts, or a function that takes the changeset and context. See the [manual actions guide](/documentation/topics/manual-actions.md) for more. | -| `get?` | `boolean` | false | Expresses that this action innately only returns a single result. Used by extensions to validate and/or modify behavior. Causes code interfaces to return a single value instead of a list. See the [code interface guide](/documentation/topics/code-interface.md) for more. | -| `modify_query` | `mfa \| (any, any -> any)` | | Allows direct manipulation of the data layer query via an MFA. The ash query and the data layer query will be provided as additional arguments. The result must be `{:ok, new_data_layer_query} \| {:error, error}`. | -| `get_by` | `atom \| list(atom)` | | A helper to automatically generate a "get by X" action. Sets `get?` to true, add args for each of the specified fields, and adds a filter for each of the arguments. | -| `primary?` | `boolean` | false | Whether or not this action should be used when no action is specified by the caller. | -| `description` | `String.t` | | An optional description for the action | -| `transaction?` | `boolean` | | Whether or not the action should be run in transactions. Reads default to false, while create/update/destroy actions default to `true`. | -| `touches_resources` | `list(atom)` | | A list of resources that the action may touch, used when building transactions. | - - -## actions.read.argument - -```elixir -argument name, type -``` - ---- - -Introspection Target: `Ash.Resource.Actions.Argument` - -Declares an argument on the action - - ---- - - - -### Examples -``` -argument :password_confirmation, :string -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the argument | -| `type` - required-arg 2 | `module` | | The type of the argument. See `Ash.Type` for more. | -| `description` | `String.t` | | An optional description for the argument. | -| `constraints` | `Keyword.t` | [] | Constraints to provide to the type when casting the value. For more information, see [the constraints topic](/documentation/topics/constraints.md). | -| `allow_nil?` | `boolean` | true | Whether or not the argument value may be nil (or may be not provided). If nil value is given error is raised. | -| `private?` | `boolean` | false | Whether or not the argument should be suppliable by the client. | -| `sensitive?` | `boolean` | false | Whether or not the argument value contains sensitive information, like PII. See the [security guide](/documentation/topics/security.md) for more. | -| `default` | ``any`` | | The default value for the argument to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value | - - - - -## actions.read.prepare - -```elixir -prepare preparation -``` - ---- - -Introspection Target: `Ash.Resource.Preparation` - -Declares a preparation, which can be used to prepare a query for a read action. - - ---- - - - -### Examples -``` -prepare build(sort: [:foo, :bar]) - -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `preparation` - required-arg 1 | `(any, any -> any) \| module` | The module and options for a preparation. Also accepts functions take the query and the context. | - - - - -## actions.read.pagination - -```elixir -pagination -``` - ---- - -Introspection Target: `Ash.Resource.Actions.Read.Pagination` - -Adds pagination options to a resource - - ---- - - - -### Examples - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `keyset?` | `boolean` | false | Whether or not keyset based pagination is supported | -| `offset?` | `boolean` | false | Whether or not offset based pagination is supported | -| `default_limit` | `pos_integer` | | The default page size to apply, if one is not supplied | -| `countable` | `true \| false \| :by_default` | false | Whether not a returned page will have a full count of all records. Use `:by_default` to do it automatically. | -| `max_page_size` | `pos_integer` | 250 | The maximum amount of records that can be requested in a single page | -| `required?` | `boolean` | true | Whether or not pagination can be disabled. Only relevant if some pagination configuration is supplied. | - - - - -## actions.read.metadata - -```elixir -metadata name, type -``` - ---- - -Introspection Target: `Ash.Resource.Actions.Metadata` - -A special kind of attribute that is only added to specific actions. Nothing sets this value, it must be set in a custom -change via `Ash.Resource.Info.put_metadata/3`. - - ---- - - - -### Examples -``` -metadata :api_token, :string, allow_nil?: false - -``` - - -``` -metadata :operation_id, :string, allow_nil?: false - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the metadata | -| `type` - required-arg 2 | ``any`` | | The type of the metadata. See `Ash.Type` for more. | -| `constraints` | `Keyword.t` | [] | Type constraints on the metadata | -| `description` | `String.t` | | An optional description for the metadata. | -| `allow_nil?` | `boolean` | true | Whether or not the metadata may return `nil` | -| `default` | ``any`` | | The default value for the metadata to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value | - - - - - - -## actions.update - -```elixir -update name -``` - ---- - -Introspection Target: `Ash.Resource.Actions.Update` - -Declares a `update` action. For calling this action, see the `Ash.Api` documentation. - - ---- - - * [change](#actions-update-change) - * [validate](#actions-update-validate) - * [metadata](#actions-update-metadata) - * [argument](#actions-update-argument) - -### Examples -``` -update :flag_for_review, primary?: true -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the action | -| `manual` | `(any, any -> any) \| module` | | Override the update behavior. Accepts a module or module and opts, or a function that takes the changeset and context. See the [manual actions guide](/documentation/topics/manual-actions.md) for more. | -| `primary?` | `boolean` | false | Whether or not this action should be used when no action is specified by the caller. | -| `description` | `String.t` | | An optional description for the action | -| `transaction?` | `boolean` | | Whether or not the action should be run in transactions. Reads default to false, while create/update/destroy actions default to `true`. | -| `touches_resources` | `list(atom)` | | A list of resources that the action may touch, used when building transactions. | -| `accept` | `:all \| list(atom)` | | The list of attributes to accept. Defaults to all attributes on the resource | -| `delay_global_validations?` | `boolean` | false | If true, global validations will be done in a `before_action` hook, regardless of their configuration on the resource. | -| `skip_global_validations?` | `boolean` | false | If true, global validations will be skipped. Useful for manual actions. | -| `reject` | `:all \| list(atom)` | | A list of attributes not to accept. If this is specified along with `accept`, these are removed from the `accept` list. | -| `require_attributes` | `list(atom)` | | A list of attributes that would normally `allow_nil?`, to require for this action. No need to include attributes that already do not allow nil? | -| `error_handler` | `mfa` | | Sets the error handler on the changeset. See `Ash.Changeset.handle_errors/2` for more | -| `manual?` | `boolean` | | Instructs Ash to *skip* the actual update/create/destroy step at the data layer. See the [manual actions guide](/documentation/topics/manual-actions.md) for more. | - - -## actions.update.change - -```elixir -change change -``` - ---- - -Introspection Target: `Ash.Resource.Change` - -A change to be applied to the changeset. - -See `Ash.Resource.Change` for more. - - ---- - - - -### Examples -``` -change relate_actor(:reporter) -``` - - -``` -change {MyCustomChange, :foo} -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `change` - required-arg 1 | `(any, any -> any) \| module` | | The module and options for a change. Also accepts a function that takes the changeset and the context. See `Ash.Resource.Change.Builtins` for builtin changes. | -| `only_when_valid?` | `boolean` | false | If the change should only be run on valid changes. By default, all changes are run unless stated otherwise here. | -| `description` | `String.t` | | An optional description for the change | -| `where` | `list((any -> any) \| module)` | [] | Validations that should pass in order for this validation to apply. These validations failing will result in this validation being ignored. | - - - - -## actions.update.validate - -```elixir -validate validation -``` - ---- - -Introspection Target: `Ash.Resource.Validation` - -Declares a validation to be applied to the changeset. - -See `Ash.Resource.Validation` for more. - - ---- - - - -### Examples -``` -validate changing(:email) -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `validation` - required-arg 1 | `(any -> any) \| module` | | The module (or module and opts) that implements the `Ash.Resource.Validation` behaviour. Also accepts a one argument function that takes the changeset. | -| `where` | `(any -> any) \| module \| list((any -> any) \| module)` | [] | Validations that should pass in order for this validation to apply. Any of these validations failing will result in this validation being ignored. | -| `only_when_valid?` | `boolean` | false | If the validation should only run on valid changes. Useful for expensive validations or validations that depend on valid data. | -| `message` | `String.t` | | If provided, overrides any message set by the validation error | -| `description` | `String.t` | | An optional description for the validation | -| `before_action?` | `boolean` | false | If set to `true`, the validation will be run in a before_action hook | - - - - -## actions.update.metadata - -```elixir -metadata name, type -``` - ---- - -Introspection Target: `Ash.Resource.Actions.Metadata` - -A special kind of attribute that is only added to specific actions. Nothing sets this value, it must be set in a custom -change via `Ash.Resource.Info.put_metadata/3`. - - ---- - - - -### Examples -``` -metadata :api_token, :string, allow_nil?: false - -``` - - -``` -metadata :operation_id, :string, allow_nil?: false - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the metadata | -| `type` - required-arg 2 | ``any`` | | The type of the metadata. See `Ash.Type` for more. | -| `constraints` | `Keyword.t` | [] | Type constraints on the metadata | -| `description` | `String.t` | | An optional description for the metadata. | -| `allow_nil?` | `boolean` | true | Whether or not the metadata may return `nil` | -| `default` | ``any`` | | The default value for the metadata to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value | - - - - -## actions.update.argument - -```elixir -argument name, type -``` - ---- - -Introspection Target: `Ash.Resource.Actions.Argument` - -Declares an argument on the action - - ---- - - - -### Examples -``` -argument :password_confirmation, :string -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the argument | -| `type` - required-arg 2 | `module` | | The type of the argument. See `Ash.Type` for more. | -| `description` | `String.t` | | An optional description for the argument. | -| `constraints` | `Keyword.t` | [] | Constraints to provide to the type when casting the value. For more information, see [the constraints topic](/documentation/topics/constraints.md). | -| `allow_nil?` | `boolean` | true | Whether or not the argument value may be nil (or may be not provided). If nil value is given error is raised. | -| `private?` | `boolean` | false | Whether or not the argument should be suppliable by the client. | -| `sensitive?` | `boolean` | false | Whether or not the argument value contains sensitive information, like PII. See the [security guide](/documentation/topics/security.md) for more. | -| `default` | ``any`` | | The default value for the argument to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value | - - - - - - -## actions.destroy - -```elixir -destroy name -``` - ---- - -Introspection Target: `Ash.Resource.Actions.Destroy` - -Declares a `destroy` action. For calling this action, see the `Ash.Api` documentation. - - ---- - - * [change](#actions-destroy-change) - * [validate](#actions-destroy-validate) - * [metadata](#actions-destroy-metadata) - * [argument](#actions-destroy-argument) - -### Examples -``` -destroy :soft_delete do - primary? true -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the action | -| `soft?` | `atom` | false | If specified, the destroy action behaves as an update internally | -| `manual` | `(any, any -> any) \| module` | | Override the update behavior. Accepts a module or module and opts, or a function that takes the changeset and context. See the [manual actions guide](/documentation/topics/manual-actions.md) for more. | -| `primary?` | `boolean` | false | Whether or not this action should be used when no action is specified by the caller. | -| `description` | `String.t` | | An optional description for the action | -| `transaction?` | `boolean` | | Whether or not the action should be run in transactions. Reads default to false, while create/update/destroy actions default to `true`. | -| `touches_resources` | `list(atom)` | | A list of resources that the action may touch, used when building transactions. | -| `accept` | `:all \| list(atom)` | | The list of attributes to accept. Defaults to all attributes on the resource | -| `delay_global_validations?` | `boolean` | false | If true, global validations will be done in a `before_action` hook, regardless of their configuration on the resource. | -| `skip_global_validations?` | `boolean` | false | If true, global validations will be skipped. Useful for manual actions. | -| `reject` | `:all \| list(atom)` | | A list of attributes not to accept. If this is specified along with `accept`, these are removed from the `accept` list. | -| `require_attributes` | `list(atom)` | | A list of attributes that would normally `allow_nil?`, to require for this action. No need to include attributes that already do not allow nil? | -| `error_handler` | `mfa` | | Sets the error handler on the changeset. See `Ash.Changeset.handle_errors/2` for more | -| `manual?` | `boolean` | | Instructs Ash to *skip* the actual update/create/destroy step at the data layer. See the [manual actions guide](/documentation/topics/manual-actions.md) for more. | - - -## actions.destroy.change - -```elixir -change change -``` - ---- - -Introspection Target: `Ash.Resource.Change` - -A change to be applied to the changeset. - -See `Ash.Resource.Change` for more. - - ---- - - - -### Examples -``` -change relate_actor(:reporter) -``` - - -``` -change {MyCustomChange, :foo} -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `change` - required-arg 1 | `(any, any -> any) \| module` | | The module and options for a change. Also accepts a function that takes the changeset and the context. See `Ash.Resource.Change.Builtins` for builtin changes. | -| `only_when_valid?` | `boolean` | false | If the change should only be run on valid changes. By default, all changes are run unless stated otherwise here. | -| `description` | `String.t` | | An optional description for the change | -| `where` | `list((any -> any) \| module)` | [] | Validations that should pass in order for this validation to apply. These validations failing will result in this validation being ignored. | - - - - -## actions.destroy.validate - -```elixir -validate validation -``` - ---- - -Introspection Target: `Ash.Resource.Validation` - -Declares a validation to be applied to the changeset. - -See `Ash.Resource.Validation` for more. - - ---- - - - -### Examples -``` -validate changing(:email) -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `validation` - required-arg 1 | `(any -> any) \| module` | | The module (or module and opts) that implements the `Ash.Resource.Validation` behaviour. Also accepts a one argument function that takes the changeset. | -| `where` | `(any -> any) \| module \| list((any -> any) \| module)` | [] | Validations that should pass in order for this validation to apply. Any of these validations failing will result in this validation being ignored. | -| `only_when_valid?` | `boolean` | false | If the validation should only run on valid changes. Useful for expensive validations or validations that depend on valid data. | -| `message` | `String.t` | | If provided, overrides any message set by the validation error | -| `description` | `String.t` | | An optional description for the validation | -| `before_action?` | `boolean` | false | If set to `true`, the validation will be run in a before_action hook | - - - - -## actions.destroy.metadata - -```elixir -metadata name, type -``` - ---- - -Introspection Target: `Ash.Resource.Actions.Metadata` - -A special kind of attribute that is only added to specific actions. Nothing sets this value, it must be set in a custom -change via `Ash.Resource.Info.put_metadata/3`. - - ---- - - - -### Examples -``` -metadata :api_token, :string, allow_nil?: false - -``` - - -``` -metadata :operation_id, :string, allow_nil?: false - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the metadata | -| `type` - required-arg 2 | ``any`` | | The type of the metadata. See `Ash.Type` for more. | -| `constraints` | `Keyword.t` | [] | Type constraints on the metadata | -| `description` | `String.t` | | An optional description for the metadata. | -| `allow_nil?` | `boolean` | true | Whether or not the metadata may return `nil` | -| `default` | ``any`` | | The default value for the metadata to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value | - - - - -## actions.destroy.argument - -```elixir -argument name, type -``` - ---- - -Introspection Target: `Ash.Resource.Actions.Argument` - -Declares an argument on the action - - ---- - - - -### Examples -``` -argument :password_confirmation, :string -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the argument | -| `type` - required-arg 2 | `module` | | The type of the argument. See `Ash.Type` for more. | -| `description` | `String.t` | | An optional description for the argument. | -| `constraints` | `Keyword.t` | [] | Constraints to provide to the type when casting the value. For more information, see [the constraints topic](/documentation/topics/constraints.md). | -| `allow_nil?` | `boolean` | true | Whether or not the argument value may be nil (or may be not provided). If nil value is given error is raised. | -| `private?` | `boolean` | false | Whether or not the argument should be suppliable by the client. | -| `sensitive?` | `boolean` | false | Whether or not the argument value contains sensitive information, like PII. See the [security guide](/documentation/topics/security.md) for more. | -| `default` | ``any`` | | The default value for the argument to take. It can be a zero argument function e.g `&MyMod.my_fun/0` or a value | - - - - - - - - - -## code_interface -Functions that will be defined on the Api module to interact with this resource. See the [code interface guide](/documentation/topics/code-interface.md) for more. - - ---- - - * [define](#code_interface-define) - * [define_calculation](#code_interface-define_calculation) - -### Examples -``` -code_interface do - define_for MyApp.Api - define :create_user, action: :create - define :get_user_by_id, action: :get_by_id, args: [:id], get?: true -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `define_for` | `module` | false | Defines the code interface on the resource module directly, using the provided Api. | - - - -## code_interface.define - -```elixir -define name -``` - ---- - -Introspection Target: `Ash.Resource.Interface` - -Defines a function with the corresponding name and arguments. See the [code interface guide](/documentation/topics/code-interface.md) for more. - - ---- - - - -### Examples -``` -define :get_user_by_id, action: :get_by_id, args: [:id], get?: true -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the function that will be defined | -| `action` | `atom` | | The name of the action that will be called. Defaults to the same name as the function. | -| `args` | `list(atom \| {:optional, atom})` | | Map specific arguments to named inputs. Can provide any argument/attributes that the action allows. | -| `not_found_error?` | `boolean` | true | If the action or interface is configured with `get?: true`, this determines whether or not an error is raised or `nil` is returned. | -| `get?` | `boolean` | | Expects to only receive a single result from a read action, and returns a single result instead of a list. Ignored for other action types. | -| `get_by` | `list(atom)` | | Takes a list of fields and adds those fields as arguments, which will then be used to filter. Sets `get?` to true automatically. Ignored for non-read actions. | -| `get_by_identity` | `atom` | | Only relevant for read actions. Takes an identity, and gets its field list, performing the same logic as `get_by` once it has the list of fields. | - - - - -## code_interface.define_calculation - -```elixir -define_calculation name -``` - ---- - -Introspection Target: `Ash.Resource.CalculationInterface` - -Defines a function with the corresponding name and arguments, that evaluates a calculation. Use `:_record` to take an instance of a record. See the [code interface guide](/documentation/topics/code-interface.md) for more. - - ---- - - - -### Examples -``` -define_calculation :referral_link, args: [:id] -``` - - -``` -define_calculation :referral_link, args: [{:arg, :id}, {:ref, :id}] -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the function that will be defined | -| `calculation` | `atom` | | The name of the calculation that will be evaluated. Defaults to the same name as the function. | -| `args` | ``any`` | [] | Supply field or argument values referenced by the calculation, in the form of :name, `{:arg, :name}` and/or `{:ref, :name}`. See the [code interface guide](/documentation/topics/code-interface.md) for more. | - - - - - - - -## resource -General resource configuration - - ---- - - - -### Examples -``` -resource do - description "A description of this resource" - base_filter [is_nil: :deleted_at] -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `description` | `String.t` | | A human readable description of the resource, to be used in generated documentation | -| `base_filter` | ``any`` | | A filter statement to be applied to any queries on the resource | -| `default_context` | ``any`` | | Default context to apply to any queries/changesets generated for this resource. | -| `trace_name` | `String.t` | | The name to use in traces. Defaults to the short_name stringified. See the [monitoring guide](/documentation/topics/monitoring.md) for more. | -| `short_name` | `atom` | | A short identifier for the resource, which should be unique. See the [monitoring guide](/documentation/topics/monitoring.md) for more. | -| `plural_name` | `atom` | | A pluralized version of the resource short_name. May be used by generators or automated tooling. | -| `simple_notifiers` | `list(module)` | | A list of notifiers that require no DSL. Can be used to avoid compile time dependencies on notifiers | -| `require_primary_key?` | `boolean` | true | Allow the resource to be used without any primary key fields. Warning: this option is experimental, and should not be used unless you know what you're doing. | - - - - - - -## identities - ---- - - * [identity](#identities-identity) - -### Examples -``` -identities do - identity :full_name, [:first_name, :last_name] - identity :email, [:email] -end - -``` - - - -## identities.identity - -```elixir -identity name, keys -``` - ---- - -Introspection Target: `Ash.Resource.Identity` - -Represents a unique constraint on the resource. - -See the [identities guide](/documentation/topics/identities.md) for more. - - ---- - - - -### Examples -``` -identity :name, [:name] -``` - - -``` -identity :full_name, [:first_name, :last_name] -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `name` - required-arg 1 | `atom` | The name of the identity. | -| `keys` - required-arg 2 | ``any`` | The names of the attributes that uniquely identify this resource. | -| `eager_check_with` | `module` | Validates that the unique identity provided is unique at validation time, outside of any transactions, using the api module provided. | -| `pre_check_with` | `module` | Validates that the unique identity provided is unique in a before_action hook. | -| `description` | `String.t` | An optional description for the identity | -| `message` | `String.t` | An error message to use when the unique identity would be violated | - - - - - - - -## changes - ---- - - * [change](#changes-change) - -### Examples -``` -changes do - change {Mod, [foo: :bar]} - change set_context(%{some: :context}) -end - -``` - - - -## changes.change - -```elixir -change change -``` - ---- - -Introspection Target: `Ash.Resource.Change` - -A change to be applied to the changeset. - -See `Ash.Resource.Change` for more. - - ---- - - - -### Examples -``` -change relate_actor(:reporter) -``` - - -``` -change {MyCustomChange, :foo} -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `change` - required-arg 1 | `(any, any -> any) \| module` | | The module and options for a change. Also accepts a function that takes the changeset and the context. See `Ash.Resource.Change.Builtins` for builtin changes. | -| `on` | ``any`` | [:create, :update] | The action types the validation should run on. Destroy actions are omitted by default as most changes don't make sense for a destroy. | -| `only_when_valid?` | `boolean` | false | If the change should only be run on valid changes. By default, all changes are run unless stated otherwise here. | -| `description` | `String.t` | | An optional description for the change | -| `where` | `list((any -> any) \| module)` | [] | Validations that should pass in order for this validation to apply. These validations failing will result in this validation being ignored. | - - - - - - - -## preparations - ---- - - * [prepare](#preparations-prepare) - -### Examples -``` -preparations do - prepare {Mod, [foo: :bar]} - prepare set_context(%{some: :context}) -end - -``` - - - -## preparations.prepare - -```elixir -prepare preparation -``` - ---- - -Introspection Target: `Ash.Resource.Preparation` - -Declares a preparation, which can be used to prepare a query for a read action. - - ---- - - - -### Examples -``` -prepare build(sort: [:foo, :bar]) - -``` - - -### Reference -| Name | Type | Docs | -| --- | --- | --- | -| `preparation` - required-arg 1 | `(any, any -> any) \| module` | The module and options for a preparation. Also accepts functions take the query and the context. | - - - - - - - -## validations - ---- - - * [validate](#validations-validate) - -### Examples -``` -validations do - validate {Mod, [foo: :bar]} - validate at_least_one_of_present([:first_name, :last_name]) -end - -``` - - - -## validations.validate - -```elixir -validate validation -``` - ---- - -Introspection Target: `Ash.Resource.Validation` - -Declares a validation for creates and updates. - -See `Ash.Resource.Change` for more. - - ---- - - - -### Examples -``` -validate {Mod, [foo: :bar]} -``` - - -``` -validate at_least_one_of_present([:first_name, :last_name]) -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `validation` - required-arg 1 | `(any -> any) \| module` | | The module (or module and opts) that implements the `Ash.Resource.Validation` behaviour. Also accepts a one argument function that takes the changeset. | -| `where` | `(any -> any) \| module \| list((any -> any) \| module)` | [] | Validations that should pass in order for this validation to apply. Any of these validations failing will result in this validation being ignored. | -| `on` | ``any`` | [:create, :update] | The action types the validation should run on. Many validations don't make sense in the context of deletion, so by default it is not included. | -| `only_when_valid?` | `boolean` | false | If the validation should only run on valid changes. Useful for expensive validations or validations that depend on valid data. | -| `message` | `String.t` | | If provided, overrides any message set by the validation error | -| `description` | `String.t` | | An optional description for the validation | -| `before_action?` | `boolean` | false | If set to `true`, the validation will be run in a before_action hook | - - - - - - - -## aggregates - ---- - - * [count](#aggregates-count) - * [exists](#aggregates-exists) - * [first](#aggregates-first) - * [sum](#aggregates-sum) - * [list](#aggregates-list) - * [max](#aggregates-max) - * [min](#aggregates-min) - * [avg](#aggregates-avg) - * [custom](#aggregates-custom) - -### Examples -``` -aggregates do - count :assigned_ticket_count, :reported_tickets do - filter [active: true] - end -end - -``` - - - -## aggregates.count - -```elixir -count name, relationship_path -``` - ---- - -Introspection Target: `Ash.Resource.Aggregate` - -Declares a named count aggregate on the resource - -Supports `filter`, but not `sort` (because that wouldn't affect the count) - -See the [aggregates guide](/documentation/topics/aggregates.md) for more. - - ---- - - - -### Examples -``` -count :assigned_ticket_count, :assigned_tickets do - filter [active: true] -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The field to place the aggregate in | -| `relationship_path` - required-arg 2 | ``any`` | | The relationship or relationship path to use for the aggregate | -| `uniq?` | `boolean` | false | Wether or not to count unique values only | -| `read_action` | `atom` | | The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments. | -| `kind` - required | `:count \| :first \| :sum \| :list \| :avg \| :max \| :min \| :exists \| :custom \| {:custom, module}` | | The kind of the aggregate | -| `field` | `atom` | | The field to aggregate. Defaults to the first field in the primary key of the resource | -| `filter` | ``any`` | [] | A filter to apply to the aggregate | -| `description` | `String.t` | | An optional description for the aggregate | -| `default` | ``any`` | | A default value to use in cases where nil would be used. Count defaults to `0`. | -| `private?` | `boolean` | false | Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql | -| `filterable?` | `boolean \| :simple_equality` | true | Whether or not the aggregate should be usable in filters. | -| `authorize?` | `boolean` | true | Wether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action. | - - - - -## aggregates.exists - -```elixir -exists name, relationship_path -``` - ---- - -Introspection Target: `Ash.Resource.Aggregate` - -Declares a named `exists` aggregate on the resource - -Supports `filter`, but not `sort` (because that wouldn't affect if something exists) - -See the [aggregates guide](/documentation/topics/aggregates.md) for more. - - ---- - - - -### Examples -``` -exists :has_ticket, :assigned_tickets - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The field to place the aggregate in | -| `relationship_path` - required-arg 2 | ``any`` | | The relationship or relationship path to use for the aggregate | -| `read_action` | `atom` | | The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments. | -| `kind` - required | `:count \| :first \| :sum \| :list \| :avg \| :max \| :min \| :exists \| :custom \| {:custom, module}` | | The kind of the aggregate | -| `filter` | ``any`` | [] | A filter to apply to the aggregate | -| `description` | `String.t` | | An optional description for the aggregate | -| `default` | ``any`` | | A default value to use in cases where nil would be used. Count defaults to `0`. | -| `private?` | `boolean` | false | Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql | -| `filterable?` | `boolean \| :simple_equality` | true | Whether or not the aggregate should be usable in filters. | -| `authorize?` | `boolean` | true | Wether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action. | - - - - -## aggregates.first - -```elixir -first name, relationship_path, field -``` - ---- - -Introspection Target: `Ash.Resource.Aggregate` - -Declares a named `first` aggregate on the resource - -First aggregates return the first value of the related record -that matches. Supports both `filter` and `sort`. - -See the [aggregates guide](/documentation/topics/aggregates.md) for more. - - ---- - - - -### Examples -``` -first :first_assigned_ticket_subject, :assigned_tickets, :subject do - filter [active: true] - sort [:subject] -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The field to place the aggregate in | -| `relationship_path` - required-arg 2 | ``any`` | | The relationship or relationship path to use for the aggregate | -| `field` - arg 3 | `atom` | | The field to aggregate. Defaults to the first field in the primary key of the resource | -| `read_action` | `atom` | | The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments. | -| `kind` - required | `:count \| :first \| :sum \| :list \| :avg \| :max \| :min \| :exists \| :custom \| {:custom, module}` | | The kind of the aggregate | -| `filter` | ``any`` | [] | A filter to apply to the aggregate | -| `sort` | ``any`` | | A sort to be applied to the aggregate | -| `description` | `String.t` | | An optional description for the aggregate | -| `default` | ``any`` | | A default value to use in cases where nil would be used. Count defaults to `0`. | -| `private?` | `boolean` | false | Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql | -| `filterable?` | `boolean \| :simple_equality` | true | Whether or not the aggregate should be usable in filters. | -| `authorize?` | `boolean` | true | Wether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action. | - - - - -## aggregates.sum - -```elixir -sum name, relationship_path, field -``` - ---- - -Introspection Target: `Ash.Resource.Aggregate` - -Declares a named `sum` aggregate on the resource - -Supports `filter`, but not `sort` (because that wouldn't affect the sum) - -See the [aggregates guide](/documentation/topics/aggregates.md) for more. - - ---- - - - -### Examples -``` -sum :assigned_ticket_price_sum, :assigned_tickets, :price do - filter [active: true] -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The field to place the aggregate in | -| `relationship_path` - required-arg 2 | ``any`` | | The relationship or relationship path to use for the aggregate | -| `field` - arg 3 | `atom` | | The field to aggregate. Defaults to the first field in the primary key of the resource | -| `read_action` | `atom` | | The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments. | -| `kind` - required | `:count \| :first \| :sum \| :list \| :avg \| :max \| :min \| :exists \| :custom \| {:custom, module}` | | The kind of the aggregate | -| `filter` | ``any`` | [] | A filter to apply to the aggregate | -| `description` | `String.t` | | An optional description for the aggregate | -| `default` | ``any`` | | A default value to use in cases where nil would be used. Count defaults to `0`. | -| `private?` | `boolean` | false | Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql | -| `filterable?` | `boolean \| :simple_equality` | true | Whether or not the aggregate should be usable in filters. | -| `authorize?` | `boolean` | true | Wether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action. | - - - - -## aggregates.list - -```elixir -list name, relationship_path, field -``` - ---- - -Introspection Target: `Ash.Resource.Aggregate` - -Declares a named `list` aggregate on the resource. - -A list aggregate selects the list of all values for the given field -and relationship combination. - -See the [aggregates guide](/documentation/topics/aggregates.md) for more. - - ---- - - - -### Examples -``` -list :assigned_ticket_prices, :assigned_tickets, :price do - filter [active: true] -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The field to place the aggregate in | -| `relationship_path` - required-arg 2 | ``any`` | | The relationship or relationship path to use for the aggregate | -| `field` - arg 3 | `atom` | | The field to aggregate. Defaults to the first field in the primary key of the resource | -| `uniq?` | `boolean` | false | Wether or not to count unique values only | -| `read_action` | `atom` | | The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments. | -| `kind` - required | `:count \| :first \| :sum \| :list \| :avg \| :max \| :min \| :exists \| :custom \| {:custom, module}` | | The kind of the aggregate | -| `filter` | ``any`` | [] | A filter to apply to the aggregate | -| `sort` | ``any`` | | A sort to be applied to the aggregate | -| `description` | `String.t` | | An optional description for the aggregate | -| `default` | ``any`` | | A default value to use in cases where nil would be used. Count defaults to `0`. | -| `private?` | `boolean` | false | Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql | -| `filterable?` | `boolean \| :simple_equality` | true | Whether or not the aggregate should be usable in filters. | -| `authorize?` | `boolean` | true | Wether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action. | - - - - -## aggregates.max - -```elixir -max name, relationship_path, field -``` - ---- - -Introspection Target: `Ash.Resource.Aggregate` - -Declares a named `max` aggregate on the resource - -Supports `filter`, but not `sort` (because that wouldn't affect the max) - -See the [aggregates guide](/documentation/topics/aggregates.md) for more. - - ---- - - - -### Examples -``` -max :first_assigned_ticket_subject, :assigned_tickets, :severity do - filter [active: true] -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The field to place the aggregate in | -| `relationship_path` - required-arg 2 | ``any`` | | The relationship or relationship path to use for the aggregate | -| `field` - arg 3 | `atom` | | The field to aggregate. Defaults to the first field in the primary key of the resource | -| `read_action` | `atom` | | The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments. | -| `kind` - required | `:count \| :first \| :sum \| :list \| :avg \| :max \| :min \| :exists \| :custom \| {:custom, module}` | | The kind of the aggregate | -| `filter` | ``any`` | [] | A filter to apply to the aggregate | -| `description` | `String.t` | | An optional description for the aggregate | -| `default` | ``any`` | | A default value to use in cases where nil would be used. Count defaults to `0`. | -| `private?` | `boolean` | false | Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql | -| `filterable?` | `boolean \| :simple_equality` | true | Whether or not the aggregate should be usable in filters. | -| `authorize?` | `boolean` | true | Wether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action. | - - - - -## aggregates.min - -```elixir -min name, relationship_path, field -``` - ---- - -Introspection Target: `Ash.Resource.Aggregate` - -Declares a named `min` aggregate on the resource - -Supports `filter`, but not `sort` (because that wouldn't affect the min) - -See the [aggregates guide](/documentation/topics/aggregates.md) for more. - - ---- - - - -### Examples -``` -min :first_assigned_ticket_subject, :assigned_tickets, :severity do - filter [active: true] -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The field to place the aggregate in | -| `relationship_path` - required-arg 2 | ``any`` | | The relationship or relationship path to use for the aggregate | -| `field` - arg 3 | `atom` | | The field to aggregate. Defaults to the first field in the primary key of the resource | -| `read_action` | `atom` | | The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments. | -| `kind` - required | `:count \| :first \| :sum \| :list \| :avg \| :max \| :min \| :exists \| :custom \| {:custom, module}` | | The kind of the aggregate | -| `filter` | ``any`` | [] | A filter to apply to the aggregate | -| `description` | `String.t` | | An optional description for the aggregate | -| `default` | ``any`` | | A default value to use in cases where nil would be used. Count defaults to `0`. | -| `private?` | `boolean` | false | Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql | -| `filterable?` | `boolean \| :simple_equality` | true | Whether or not the aggregate should be usable in filters. | -| `authorize?` | `boolean` | true | Wether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action. | - - - - -## aggregates.avg - -```elixir -avg name, relationship_path, field -``` - ---- - -Introspection Target: `Ash.Resource.Aggregate` - -Declares a named `avg` aggregate on the resource - -Supports `filter`, but not `sort` (because that wouldn't affect the avg) - -See the [aggregates guide](/documentation/topics/aggregates.md) for more. - - ---- - - - -### Examples -``` -avg :assigned_ticket_price_sum, :assigned_tickets, :price do - filter [active: true] -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The field to place the aggregate in | -| `relationship_path` - required-arg 2 | ``any`` | | The relationship or relationship path to use for the aggregate | -| `field` - arg 3 | `atom` | | The field to aggregate. Defaults to the first field in the primary key of the resource | -| `read_action` | `atom` | | The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments. | -| `kind` - required | `:count \| :first \| :sum \| :list \| :avg \| :max \| :min \| :exists \| :custom \| {:custom, module}` | | The kind of the aggregate | -| `filter` | ``any`` | [] | A filter to apply to the aggregate | -| `description` | `String.t` | | An optional description for the aggregate | -| `default` | ``any`` | | A default value to use in cases where nil would be used. Count defaults to `0`. | -| `private?` | `boolean` | false | Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql | -| `filterable?` | `boolean \| :simple_equality` | true | Whether or not the aggregate should be usable in filters. | -| `authorize?` | `boolean` | true | Wether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action. | - - - - -## aggregates.custom - -```elixir -custom name, relationship_path, type -``` - ---- - -Introspection Target: `Ash.Resource.Aggregate` - -Declares a named `custom` aggregate on the resource - -Supports `filter` and `sort`. - -Custom aggregates provide an `implementation` which must implement data layer specific callbacks. - -See the relevant data layer documentation and the [aggregates guide](/documentation/topics/aggregates.md) for more. - - ---- - - - -### Examples -``` -custom :author_names, :authors, :string do - implementation {StringAgg, delimiter: ","} -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The field to place the aggregate in | -| `relationship_path` - required-arg 2 | ``any`` | | The relationship or relationship path to use for the aggregate | -| `type` - required-arg 3 | `module` | | The type of the value returned by the aggregate | -| `implementation` - required | `module` | | The module that implements the relevant data layer callbacks | -| `read_action` | `atom` | | The read action to use when building the aggregate. Defaults to the primary read action. Keep in mind this action must not have any required arguments. | -| `kind` - required | `:count \| :first \| :sum \| :list \| :avg \| :max \| :min \| :exists \| :custom \| {:custom, module}` | | The kind of the aggregate | -| `field` | `atom` | | The field to aggregate. Defaults to the first field in the primary key of the resource | -| `filter` | ``any`` | [] | A filter to apply to the aggregate | -| `sort` | ``any`` | | A sort to be applied to the aggregate | -| `description` | `String.t` | | An optional description for the aggregate | -| `default` | ``any`` | | A default value to use in cases where nil would be used. Count defaults to `0`. | -| `private?` | `boolean` | false | Whether or not the aggregate will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql | -| `filterable?` | `boolean \| :simple_equality` | true | Whether or not the aggregate should be usable in filters. | -| `authorize?` | `boolean` | true | Wether or not the aggregate query should authorize based on the target action, if the parent query is authorized. Requires filter checks on the target action. | - - - - - - - -## calculations - ---- - - * [calculate](#calculations-calculate) - * argument - -### Examples -``` -calculations do - calculate :full_name, :string, MyApp.MyResource.FullName -end - -``` - - - -## calculations.calculate - -```elixir -calculate name, type, calculation \ nil -``` - ---- - -Introspection Target: `Ash.Resource.Calculation` - -Declares a named calculation on the resource. - -Takes a module that must adopt the `Ash.Calculation` behaviour. See that module -for more information. - -To ensure that the necessary fields are selected: - -1.) Specifying the `select` option on a calculation in the resource. -2.) Define a `select/2` callback in the calculation module -3.) Set `always_select?` on the attribute in question - -See the [calculations guide](/documentation/topics/calculations.md) for more. - - ---- - - * [argument](#calculations-calculate-argument) - -### Examples -`Ash.Calculation` implementation example: -``` -calculate :full_name, :string, {MyApp.FullName, keys: [:first_name, :last_name]}, select: [:first_name, :last_name] -``` - - -`expr/1` example: -``` -calculate :full_name, :string, expr(first_name <> " " <> last_name) -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The field name to use for the calculation value | -| `type` - required-arg 2 | ``any`` | | The type of the calculation. See `Ash.Type` for more. | -| `calculation` - required-arg 3 | `(any, any -> any) \| module \| `any`` | | The `module`, `{module, opts}` or `expr(...)` to use for the calculation. Also accepts a function that takes *a single record* and produces the result. | -| `constraints` | `Keyword.t` | [] | Constraints to provide to the type. See `Ash.Type` for more. | -| `description` | `String.t` | | An optional description for the calculation | -| `private?` | `boolean` | false | Whether or not the calculation will appear in any interfaces created off of this resource, e.g AshJsonApi and AshGraphql See the [security guide](/documentation/topics/security.md) for more. | -| `select` | `list(atom)` | [] | A list of fields to ensure selected if the calculation is used. | -| `load` | ``any`` | [] | A load statement to be applied if the calculation is used. | -| `allow_nil?` | `boolean` | true | Whether or not the calculation can return nil. | -| `filterable?` | `boolean \| :simple_equality` | true | Whether or not the calculation should be usable in filters. | - - -## calculations.calculate.argument - -```elixir -argument name, type -``` - ---- - -Introspection Target: `Ash.Resource.Calculation.Argument` - -An argument to be passed into the calculation's arguments map - -See the [calculations guide](/documentation/topics/calculations.md) for more. - - ---- - - - -### Examples -``` -argument :params, :map do - default %{} -end - -``` - - -``` -argument :retries, :integer do - allow_nil? false -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `name` - required-arg 1 | `atom` | | The name of the argument | -| `type` - required-arg 2 | `module` | | The type of the argument. See `Ash.Type` for more. | -| `default` | `(-> any) \| mfa \| any()` | | A default value to use for the argument if not provided | -| `allow_nil?` | `boolean` | true | Whether or not the argument value may be nil (or may be not provided) | -| `allow_expr?` | `boolean` | false | Allow passing expressions as argument values. Expressions cannot be type validated. | -| `constraints` | `Keyword.t` | [] | Constraints to provide to the type when casting the value. See the type's documentation and `Ash.Type` for more. | - - - - - - - - - -## multitenancy -Options for configuring the multitenancy behavior of a resource. - -To specify a tenant, use `Ash.Query.set_tenant/2` or -`Ash.Changeset.set_tenant/2` before passing it to an operation. - -See the [multitenancy guide](/documentation/topics/multitenancy.md) - - ---- - - - -### Examples -``` -multitenancy do - strategy :attribute - attribute :organization_id - global? true -end - -``` - - -### Reference -| Name | Type | Default | Docs | -| --- | --- | --- | --- | -| `strategy` | `:context \| :attribute` | :context | Determine if multitenancy is performed with attribute filters or using data layer features. | -| `attribute` | `atom` | | If using the `attribute` strategy, the attribute to use, e.g `org_id` | -| `global?` | `boolean` | false | Whether or not the data also exists outside of each tenant. | -| `parse_attribute` | `mfa` | {Ash.Resource.Dsl, :identity, []} | An mfa ({module, function, args}) pointing to a function that takes a tenant and returns the attribute value | - - - - - -