This module validates and evaluates the protocol predicate algebra.
Use it when handling deterministic predicates over named input ports.
This module does not authorize operations.
Example
predicate = {:object, [{"op", {:string, "present"}}, {"path", {:array, [{:string, "request"}]}}]}
AgentBlueprintProtocol.Predicate.validate(predicate, ["request"])
Summary
Functions
Evaluates a predicate against the supplied port values.
Checks whether the supplied predicate has a valid shape for the given ports.
Functions
@spec evaluate(AgentBlueprintProtocol.Json.value(), %{ optional(binary()) => AgentBlueprintProtocol.Json.value() }) :: {:ok, boolean()} | {:error, AgentBlueprintProtocol.Error.t()}
Evaluates a predicate against the supplied port values.
Example
iex> predicate = {:object, [{"op", {:string, "eq"}}, {"path", {:array, [{:string, "request"}, {:string, "name"}]}}, {"value", {:string, "Ada"}}]}
iex> ports = %{"request" => {:object, [{"name", {:string, "Ada"}}]}}
iex> AgentBlueprintProtocol.Predicate.evaluate(predicate, ports)
{:ok, true}
@spec validate(AgentBlueprintProtocol.Json.value(), [binary()] | :any_root) :: :ok | {:error, AgentBlueprintProtocol.Error.t()}
Checks whether the supplied predicate has a valid shape for the given ports.
Example
iex> predicate = {:object, [{"op", {:string, "eq"}}, {"path", {:array, [{:string, "request"}, {:string, "name"}]}}, {"value", {:string, "Ada"}}]}
iex> AgentBlueprintProtocol.Predicate.validate(predicate, ["request"])
:ok