ash/lib/ash.ex

56 lines
1.9 KiB
Elixir
Raw Normal View History

2019-10-03 16:08:36 +13:00
defmodule Ash do
2020-10-10 03:13:44 +13:00
@moduledoc " Types and simple helpers for Ash"
2020-06-02 17:47:25 +12:00
alias Ash.Resource.Actions.{Create, Destroy, Read, Update}
alias Ash.Resource.Relationships.{BelongsTo, HasMany, HasOne, ManyToMany}
2020-01-14 07:16:24 +13:00
@type action :: Create.t() | Read.t() | Update.t() | Destroy.t()
@type action_type :: :read | :create | :update | :destroy
@type actor :: Ash.record()
@type aggregate :: Ash.Query.Aggregate.t() | Ash.Resource.Aggregate.t()
2020-08-09 05:55:36 +12:00
@type aggregate_kind :: Ash.Query.Aggregate.kind()
@type api :: module
@type attribute :: Ash.Resource.Attribute.t()
@type calculation :: Ash.Resource.Calculation.t()
2019-10-07 09:36:06 +13:00
@type cardinality_many_relationship() :: HasMany.t() | ManyToMany.t()
@type cardinality_one_relationship() :: HasOne.t() | BelongsTo.t()
@type changeset :: Ash.Changeset.t()
2019-12-05 20:18:13 +13:00
@type data_layer :: module
@type data_layer_query :: struct
2019-10-07 09:36:06 +13:00
@type error :: struct
2020-08-09 05:55:36 +12:00
@type filter :: Ash.Filter.t()
2019-12-23 17:28:40 +13:00
@type params :: Keyword.t()
@type primary_key :: record() | map | term
@type query :: Ash.Query.t()
@type record :: struct
@type relationship :: cardinality_one_relationship() | cardinality_many_relationship()
@type relationship_cardinality :: :many | :one
@type resource :: module
@type side_loads :: term
2020-10-12 16:55:47 +13:00
@type page :: Ash.Page.Keyset.t() | Ash.Page.Offset.t()
2020-09-23 02:50:46 +12:00
@type sort :: list(atom | {atom, :asc} | {atom, :desc})
@type validation :: Ash.Resource.Validation.t()
2020-10-15 17:54:02 +13:00
@type notification :: Ash.Notifier.Notification.t()
2020-05-21 10:59:58 +12:00
require Ash.Dsl.Extension
2019-10-04 15:33:55 +13:00
def implements_behaviour?(module, behaviour) do
:attributes
|> module.module_info()
|> Enum.flat_map(fn
{:behaviour, value} -> List.wrap(value)
_ -> []
end)
|> Enum.any?(&(&1 == behaviour))
end
2020-09-04 16:59:32 +12:00
def uuid do
Ecto.UUID.generate()
end
@doc "Returns all extensions of a resource or api"
@spec extensions(resource() | api()) :: [module]
def extensions(resource) do
:persistent_term.get({resource, :extensions}, [])
end
2019-10-03 16:08:36 +13:00
end