Boxic.FEEL.ExternalFunctions (boxic_feel v0.2.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.

to_context(module) deprecated

Compatibility adapter that merges a registry into a FEEL 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)

This function is deprecated. pass external_functions: to Boxic.FEEL.evaluate/3 instead.
@spec to_context(t() | module()) :: map()

Compatibility adapter that merges a registry into a FEEL context.

New code should pass external_functions: to Boxic.FEEL.evaluate/3.