AshBackendDrivenOptimisticUi. Compiler
(AshBackendDrivenOptimisticUi v0.1.0)
Copy Markdown
View Source
Compiles an unhydrated Ash.Expr term to JSON Logic, as plain maps and
lists ready for Jason.
Variables: an attribute, calculation or aggregate reads record.<name>, an
argument reads input.<name>, a context value reads ctx.<name> (a context
path is dotted, ctx.copy.title), event(:key) reads event.<key>, the
payload of the pushed event a reaction answers.
Standard operators: + - * / (and unary -), == != < > <= >=, cat
(from <>, nested ones flattened), in, and, or, ! (from not), if; is_nil(x) becomes
x == nil; has_arg(:name) becomes has, true when the input carries the
key, even with a null value, so a rule can leave alone a field the caller
did not send.
Every compared value that is not a number literal is cast to a number with
+, because Ash sends decimals as text and standard JSON Logic would
compare two such texts as text ("10.5" >= "9" is false). Every joined
value that is not a text literal is wrapped in to_string, because
standard cat prints an empty value as null and an Ash developer expects
nothing.
Custom operators the client's evaluator implements on top of JSON Logic:
abs—abs(x)round—round(x)andround(x, places)to_string—to_string(x)now—now(), the current UTC time as ISO 8601 texthas—{"has": "input.name"}, whether the path's last key is present
Decimals become floats. Anything else, including references through a
relationship and the actor, is {:error, {:unsupported, node}}.
Summary
Functions
Compiles expression, or names the first node the client cannot run.
Types
@type json_logic() :: number() | String.t() | boolean() | nil | [json_logic()] | %{required(String.t()) => json_logic()}
Functions
@spec compile(term()) :: {:ok, json_logic()} | {:error, {:unsupported, term()}}
Compiles expression, or names the first node the client cannot run.