diff --git a/lib/ash_hq/accounts/resources/user/user.ex b/lib/ash_hq/accounts/resources/user/user.ex index 430d36d..37c27da 100644 --- a/lib/ash_hq/accounts/resources/user/user.ex +++ b/lib/ash_hq/accounts/resources/user/user.ex @@ -215,9 +215,10 @@ defmodule AshHq.Accounts.User do end relationships do - has_one :token, AshHq.Accounts.UserToken, - destination_field: :user_id, - private?: true + has_one :token, AshHq.Accounts.UserToken do + destination_attribute :user_id + private? true + end end resource do diff --git a/lib/ash_hq/docs/extensions/render_markdown/render_markdown.ex b/lib/ash_hq/docs/extensions/render_markdown/render_markdown.ex index 8d383ea..8708ca6 100644 --- a/lib/ash_hq/docs/extensions/render_markdown/render_markdown.ex +++ b/lib/ash_hq/docs/extensions/render_markdown/render_markdown.ex @@ -3,7 +3,7 @@ defmodule AshHq.Docs.Extensions.RenderMarkdown do Sets up markdown text attributes to be transformed to html (in another column). """ - @render_markdown %Ash.Dsl.Section{ + @render_markdown %Spark.Dsl.Section{ name: :render_markdown, schema: [ render_attributes: [ @@ -20,16 +20,16 @@ defmodule AshHq.Docs.Extensions.RenderMarkdown do ] } - use Ash.Dsl.Extension, + use Spark.Dsl.Extension, sections: [@render_markdown], transformers: [AshHq.Docs.Extensions.RenderMarkdown.Transformers.AddRenderMarkdownStructure] def render_attributes(resource) do - Ash.Dsl.Extension.get_opt(resource, [:render_markdown], :render_attributes, []) + Spark.Dsl.Extension.get_opt(resource, [:render_markdown], :render_attributes, []) end def header_ids?(resource) do - Ash.Dsl.Extension.get_opt(resource, [:render_markdown], :header_ids?, []) + Spark.Dsl.Extension.get_opt(resource, [:render_markdown], :header_ids?, []) end def render!(%resource{} = record, key, on_demand? \\ false) do diff --git a/lib/ash_hq/docs/extensions/render_markdown/transformers/add_render_markdown_structure.ex b/lib/ash_hq/docs/extensions/render_markdown/transformers/add_render_markdown_structure.ex index 26a53e1..80637ba 100644 --- a/lib/ash_hq/docs/extensions/render_markdown/transformers/add_render_markdown_structure.ex +++ b/lib/ash_hq/docs/extensions/render_markdown/transformers/add_render_markdown_structure.ex @@ -6,16 +6,16 @@ defmodule AshHq.Docs.Extensions.RenderMarkdown.Transformers.AddRenderMarkdownStr attributes to the `allow_nil_input` of each action, since it will be adding them automatically. """ - use Ash.Dsl.Transformer - alias Ash.Dsl.Transformer + use Spark.Dsl.Transformer + alias Spark.Dsl.Transformer - def transform(resource, dsl) do - resource - |> AshHq.Docs.Extensions.RenderMarkdown.render_attributes() + def transform(dsl) do + dsl + |> Transformer.get_option([:render_markdown], :render_attributes, []) |> Enum.reduce({:ok, dsl}, fn {source, destination}, {:ok, dsl} -> {:ok, dsl - |> allow_nil_input(resource, destination) + |> allow_nil_input(destination) |> Transformer.add_entity( [:changes], Transformer.build_entity!(Ash.Resource.Dsl, [:changes], :change, @@ -27,9 +27,9 @@ defmodule AshHq.Docs.Extensions.RenderMarkdown.Transformers.AddRenderMarkdownStr end) end - defp allow_nil_input(dsl, resource, destination) do - resource - |> Ash.Resource.Info.actions() + defp allow_nil_input(dsl, destination) do + dsl + |> Transformer.get_entities([:actions]) |> Enum.filter(&(&1.type == :create)) |> Enum.reduce(dsl, fn action, dsl -> Transformer.replace_entity( diff --git a/lib/ash_hq/docs/extensions/search/search.ex b/lib/ash_hq/docs/extensions/search/search.ex index c8abdd7..7f200e1 100644 --- a/lib/ash_hq/docs/extensions/search/search.ex +++ b/lib/ash_hq/docs/extensions/search/search.ex @@ -5,9 +5,9 @@ defmodule AshHq.Docs.Extensions.Search do This generally involves ensuring that there is a url safe name attribute to be used in routing, and configuring how the item will be searched for. """ - alias Ash.Dsl.Extension + alias Spark.Dsl.Extension - @search %Ash.Dsl.Section{ + @search %Spark.Dsl.Section{ name: :search, schema: [ type: [ @@ -63,7 +63,7 @@ defmodule AshHq.Docs.Extensions.Search do ] ] } - use Ash.Dsl.Extension, + use Spark.Dsl.Extension, sections: [@search], transformers: [AshHq.Docs.Extensions.Search.Transformers.AddSearchStructure] diff --git a/lib/ash_hq/docs/extensions/search/transformers/add_search_structure.ex b/lib/ash_hq/docs/extensions/search/transformers/add_search_structure.ex index d85fd0e..bfacca4 100644 --- a/lib/ash_hq/docs/extensions/search/transformers/add_search_structure.ex +++ b/lib/ash_hq/docs/extensions/search/transformers/add_search_structure.ex @@ -13,22 +13,28 @@ defmodule AshHq.Docs.Extensions.Search.Transformers.AddSearchStructure do * Adds a search action * Adds a code interface for the search action """ - use Ash.Dsl.Transformer + use Spark.Dsl.Transformer import Ash.Filter.TemplateHelpers require Ash.Query - alias Ash.Dsl.Transformer + alias Spark.Dsl.Transformer - def transform(resource, dsl_state) do - name_attribute = AshHq.Docs.Extensions.Search.name_attribute(resource) + def transform(dsl_state) do + name_attribute = Transformer.get_option(dsl_state, [:search], :name_attribute) || :name + + sanitized_name_attribute = + Transformer.get_option(dsl_state, [:search], :sanitized_name_attribute) || + :"sanitized_#{name_attribute}" config = %{ - resource: resource, name_attribute: name_attribute, - doc_attribute: AshHq.Docs.Extensions.Search.doc_attribute(resource), - library_version_attribute: AshHq.Docs.Extensions.Search.library_version_attribute(resource), - table: AshPostgres.table(resource), - sanitized_name_attribute: AshHq.Docs.Extensions.Search.sanitized_name_attribute(resource), - show_docs_on: AshHq.Docs.Extensions.Search.show_docs_on(resource) + doc_attribute: Transformer.get_option(dsl_state, [:search], :doc_attribute), + library_version_attribute: + Transformer.get_option(dsl_state, [:search], :library_version_attribute) || + :library_version_id, + table: Transformer.get_option(dsl_state, [:postgres], :table), + sanitized_name_attribute: sanitized_name_attribute, + show_docs_on: + Transformer.get_option(dsl_state, [:search], :show_docs_on) || sanitized_name_attribute } {:ok, @@ -70,7 +76,10 @@ defmodule AshHq.Docs.Extensions.Search.Transformers.AddSearchStructure do defp add_sanitized_name(dsl_state, config) do dsl_state = - if Ash.Resource.Info.attribute(config.resource, config.sanitized_name_attribute) do + if Enum.find( + Transformer.get_entities(dsl_state, [:attributes]), + &(&1.name == config.sanitized_name_attribute) + ) do dsl_state else Transformer.add_entity( @@ -87,7 +96,7 @@ defmodule AshHq.Docs.Extensions.Search.Transformers.AddSearchStructure do ) end - if AshHq.Docs.Extensions.Search.auto_sanitize_name_attribute?(config.resource) do + if Transformer.get_option(dsl_state, [:search], :auto_sanitize_name_attribute?, true) do Transformer.add_entity( dsl_state, [:changes], @@ -96,7 +105,7 @@ defmodule AshHq.Docs.Extensions.Search.Transformers.AddSearchStructure do {AshHq.Docs.Extensions.Search.Changes.SanitizeName, source: config.name_attribute, destination: config.sanitized_name_attribute, - use_path_for_name?: AshHq.Docs.Extensions.Search.use_path_for_name?(config.resource)} + use_path_for_name?: Transformer.get_option(dsl_state, [:search], :use_path_for_name?)} ) ) else diff --git a/lib/ash_hq/docs/extensions/search/types.ex b/lib/ash_hq/docs/extensions/search/types.ex index 4977e16..85ee079 100644 --- a/lib/ash_hq/docs/extensions/search/types.ex +++ b/lib/ash_hq/docs/extensions/search/types.ex @@ -4,10 +4,8 @@ defmodule AshHq.Docs.Extensions.Search.Types do """ @search_types AshHq.Docs.Registry - |> Ash.Registry.entries() - |> Enum.filter( - &(AshHq.Docs.Extensions.Search in Ash.Resource.Info.extensions(&1)) - ) + |> Ash.Registry.Info.entries() + |> Enum.filter(&(AshHq.Docs.Extensions.Search in Spark.extensions(&1))) |> Enum.map(&AshHq.Docs.Extensions.Search.type/1) |> Enum.uniq() diff --git a/lib/ash_hq/docs/resources/library/library.ex b/lib/ash_hq/docs/resources/library/library.ex index 1632ab2..a50b226 100644 --- a/lib/ash_hq/docs/resources/library/library.ex +++ b/lib/ash_hq/docs/resources/library/library.ex @@ -42,16 +42,11 @@ defmodule AshHq.Docs.Library do attribute :display_name, :string do allow_nil? false end - - attribute :track_branches, {:array, :string} do - default [] - end end aggregates do first :latest_version, :versions, :version do sort version: :desc - filter expr(contains(version, ".")) end end diff --git a/lib/ash_hq/docs/resources/library_version/library_version.ex b/lib/ash_hq/docs/resources/library_version/library_version.ex index 4dbc4d4..a07e9bf 100644 --- a/lib/ash_hq/docs/resources/library_version/library_version.ex +++ b/lib/ash_hq/docs/resources/library_version/library_version.ex @@ -107,11 +107,6 @@ defmodule AshHq.Docs.LibraryVersion do allow_nil? false end - attribute :branch, :boolean do - allow_nil? false - default false - end - attribute :default_guide, :string end diff --git a/lib/ash_hq_web/components/doc_sidebar.ex b/lib/ash_hq_web/components/doc_sidebar.ex index bac8107..0340e93 100644 --- a/lib/ash_hq_web/components/doc_sidebar.ex +++ b/lib/ash_hq_web/components/doc_sidebar.ex @@ -153,7 +153,7 @@ defmodule AshHqWeb.Components.DocSidebar do libraries |> Enum.flat_map(fn library -> library.versions - |> Enum.find(&Ash.Resource.Info.loaded?(&1, :modules)) + |> Enum.find(&Ash.Resource.loaded?(&1, :modules)) |> case do nil -> [] @@ -256,7 +256,7 @@ defmodule AshHqWeb.Components.DocSidebar do libraries |> Enum.flat_map(fn library -> library.versions - |> Enum.find(&Ash.Resource.Info.loaded?(&1, :guides)) + |> Enum.find(&Ash.Resource.loaded?(&1, :guides)) |> case do nil -> [] @@ -277,7 +277,7 @@ defmodule AshHqWeb.Components.DocSidebar do defp get_extensions(libraries) do Enum.flat_map(libraries, fn library -> library.versions - |> Enum.find(&Ash.Resource.Info.loaded?(&1, :extensions)) + |> Enum.find(&Ash.Resource.loaded?(&1, :extensions)) |> case do nil -> [] diff --git a/lib/ash_hq_web/components/search.ex b/lib/ash_hq_web/components/search.ex index 74de65e..ba85e6c 100644 --- a/lib/ash_hq_web/components/search.ex +++ b/lib/ash_hq_web/components/search.ex @@ -43,7 +43,6 @@ defmodule AshHqWeb.Components.Search do