AshDyan.Extension behaviour (AshDyan v0.6.0)

Copy Markdown View Source

Behaviour for AshDyan extensions.

Extensions allow downstream applications to add custom functionality to AshDyan without forking. An extension can:

  • Register custom analysis types
  • Register custom data layer capabilities
  • Register custom aggregate functions
  • Register pipeline hooks
  • Provide custom DSL entities

Example

defmodule MyApp.AshDyan.Extension do
  @behaviour AshDyan.Extension

  @impl true
  def analysis_types do
    %{
      funnel: MyApp.AshDyan.Funnel,
      cohort: MyApp.AshDyan.Cohort
    }
  end

  @impl true
  def data_layer_capabilities do
    %{
      MyApp.CustomDataLayer => MyApp.AshDyan.CustomCapabilities
    }
  end

  @impl true
  def custom_aggregates do
    %{
      weighted_avg: MyApp.AshDyan.WeightedAvg,
      percentile_approx: MyApp.AshDyan.PercentileApprox
    }
  end

  @impl true
  def hooks do
    %{
      before_query: [MyApp.Hooks.QueryLogger],
      after_query: [MyApp.Hooks.ResultCache],
      before_format: [MyApp.Hooks.DataTransformer],
      after_format: [MyApp.Hooks.MetadataEnricher]
    }
  end

  @impl true
  def dsl_entities do
    [
      MyApp.AshDyan.Dsl.AnalyzableFieldExtension
    ]
  end
end

Registration

Register in your application's config/config.exs:

config :ash_dyan, :extensions, [MyApp.AshDyan.Extension]

Or register multiple extensions:

config :ash_dyan, :extensions, [
  MyApp.AshDyan.Extension,
  SomeOther.AshDyan.Extension
]

Summary

Types

analysis_types()

@type analysis_types() :: %{required(atom()) => module()}

custom_aggregates()

@type custom_aggregates() :: %{required(atom()) => module()}

data_layer_capabilities()

@type data_layer_capabilities() :: %{required(module()) => module()}

dsl_entities()

@type dsl_entities() :: [module()]

hooks()

@type hooks() :: %{
  before_query: [AshDyan.Engine.Hook.t()],
  after_query: [AshDyan.Engine.Hook.t()],
  before_format: [AshDyan.Engine.Hook.t()],
  after_format: [AshDyan.Engine.Hook.t()]
}

Callbacks

analysis_types()

@callback analysis_types() :: analysis_types()

custom_aggregates()

@callback custom_aggregates() :: custom_aggregates()

data_layer_capabilities()

@callback data_layer_capabilities() :: data_layer_capabilities()

dsl_entities()

@callback dsl_entities() :: dsl_entities()

hooks()

@callback hooks() :: hooks()

Functions

analysis_types()

custom_aggregates()

data_layer_capabilities()

dsl_entities()

hooks()