Boxic.FEEL.ExternalFunctions (boxic_feel v0.1.0)

Copy Markdown View Source

Allowlisted Elixir functions exposed to FEEL evaluation.

Registries are constructed by trusted application code. FEEL and DMN model text can invoke registered names, but cannot resolve modules, functions, or atoms itself.

Summary

Functions

Adds the external-function registry DSL to a module.

Registers an allowlisted host function in a registry module.

Invokes a registered function after applying its boundary conversions.

Creates a registry, optionally from {name, callable, options} entries.

Adds or replaces one allowlisted function.

Converts a registry value or registry module into a FEEL evaluation context.

Types

boundary_type()

@type boundary_type() ::
  :feel | :number | :integer | :float | :string | :char | :boolean

callable()

@type callable() :: function() | {module(), atom()}

entry()

@type entry() :: %{
  callable: callable(),
  parameters: [boundary_type() | {:varargs, boundary_type()}],
  returns: boundary_type()
}

t()

@type t() :: %Boxic.FEEL.ExternalFunctions{
  entries: %{optional(String.t()) => entry()}
}

Functions

__using__(opts)

(macro)

Adds the external-function registry DSL to a module.

use Boxic.FEEL.ExternalFunctions

external(name, callable, opts \\ [])

(macro)

Registers an allowlisted host function in a registry module.

external "maximum", {MyApp.Math, :maximum},
  parameters: [:number, :number],
  returns: :number

invoke(external_functions, name, args)

@spec invoke(t(), String.t(), [term()]) ::
  {:ok, term()} | {:error, Boxic.FEEL.Error.t()}

Invokes a registered function after applying its boundary conversions.

Boxic.FEEL.ExternalFunctions.invoke(registry, "maximum", [
  Decimal.new("1"),
  Decimal.new("2")
])

new(entries \\ [])

@spec new([{String.t(), callable(), keyword()}]) :: t()

Creates a registry, optionally from {name, callable, options} entries.

Boxic.FEEL.ExternalFunctions.new([
  {"maximum", {MyApp.Math, :maximum}, parameters: [:number, :number]}
])

register(registry, name, callable, opts \\ [])

@spec register(t(), String.t(), callable(), keyword()) :: t()

Adds or replaces one allowlisted function.

Boxic.FEEL.ExternalFunctions.register(
  registry,
  "maximum",
  {MyApp.Math, :maximum},
  parameters: [:number, :number],
  returns: :number
)

to_context(module)

@spec to_context(t() | module()) :: map()

Converts a registry value or registry module into a FEEL evaluation context.

context = Boxic.FEEL.ExternalFunctions.to_context(MyApp.DecisionFunctions)