AgentBlueprintProtocol.Predicate (Agent Blueprint Protocol v1.1.0)

Copy Markdown View Source

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

evaluate(predicate, ports)

(since 1.0.0)
@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}

validate(predicate, port_names)

(since 1.0.0)
@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