Helpers for querying materialized ExDatalog.Knowledge for Logistiki facts.
The event under evaluation is always identified by the atom :evt inside the
Datalog program (see Logistiki.Knowledge.Facts.event_id/0).
Summary
Functions
Returns all resolved account_role facts for the current event.
True when the event is blocked by a business rule.
Returns all derived policy facts for the current event.
Returns all requires_dimension facts grouped by policy.
True when the event requires approval.
Returns all template_posting facts (for every policy).
Functions
@spec account_roles(ExDatalog.Knowledge.t()) :: %{required(atom()) => String.t()}
Returns all resolved account_role facts for the current event.
Arguments
knowledge—%ExDatalog.Knowledge{}.
Returns
%{atom() => String.t()}— role-to-account-code map (e.g.%{cash_account: "ASSETS:CASH:USD:NOSTRO", ...}).
Examples
iex> Logistiki.Knowledge.Query.account_roles(knowledge)
%{cash_account: "ASSETS:CASH:USD:NOSTRO", client_liability_account: "LIABILITIES:CLIENT_DEPOSITS:USD:ACME:OPERATING"}
@spec blocked?(ExDatalog.Knowledge.t()) :: boolean()
True when the event is blocked by a business rule.
Arguments
knowledge—%ExDatalog.Knowledge{}.
Returns
boolean()—trueifblocked(:evt)was derived.
Examples
iex> Logistiki.Knowledge.Query.blocked?(knowledge)
false
@spec policies(ExDatalog.Knowledge.t()) :: [atom()]
Returns all derived policy facts for the current event.
Arguments
knowledge—%ExDatalog.Knowledge{}— materialized knowledge.
Returns
[atom()]— the policy atoms derived for:evt(e.g.[:cash_deposit]). Empty list if no policy matched.
Examples
iex> Logistiki.Knowledge.Query.policies(knowledge)
[:cash_deposit]
@spec required_dimensions(ExDatalog.Knowledge.t()) :: %{required(atom()) => [atom()]}
Returns all requires_dimension facts grouped by policy.
Arguments
knowledge—%ExDatalog.Knowledge{}.
Returns
%{atom() => [atom()]}— policy-to-dimensions map (e.g.%{cash_deposit: [:entity_id, :currency, :account_code]}).
Examples
iex> Logistiki.Knowledge.Query.required_dimensions(knowledge)
%{cash_deposit: [:entity_id, :currency, :account_code]}
@spec requires_approval?(ExDatalog.Knowledge.t()) :: boolean()
True when the event requires approval.
Arguments
knowledge—%ExDatalog.Knowledge{}.
Returns
boolean()—trueifrequires_approval(:evt)was derived.
Examples
iex> Logistiki.Knowledge.Query.requires_approval?(knowledge)
false
@spec template_postings(ExDatalog.Knowledge.t()) :: [map()]
Returns all template_posting facts (for every policy).
Arguments
knowledge—%ExDatalog.Knowledge{}.
Returns
[map()]— posting specs with:policy,:sequence,:direction,:role,:amount_var,:currency_var.
Examples
iex> Logistiki.Knowledge.Query.template_postings(knowledge) |> hd()
%{policy: :cash_deposit, sequence: 1, direction: :debit, role: :cash_account, amount_var: :event_amount, currency_var: :event_currency}