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
endRegistration
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
@type dsl_entities() :: [module()]
@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
@callback analysis_types() :: analysis_types()
@callback custom_aggregates() :: custom_aggregates()
@callback data_layer_capabilities() :: data_layer_capabilities()
@callback dsl_entities() :: dsl_entities()
@callback hooks() :: hooks()