Liking cljdoc? Tell your friends :D

stroopwafel.core

Pure Assertions-DL engine — Datalog evaluation over facts and rules.

No crypto, no signing, no keys, no envelopes. Just facts in, decision out.

Blocks are plain maps with :facts, :rules, :checks. The caller is responsible for signature verification and fact extraction before calling evaluate. This separation means the engine has zero external dependencies and can be embedded anywhere.

Pure Assertions-DL engine — Datalog evaluation over facts and rules.

No crypto, no signing, no keys, no envelopes. Just facts in, decision out.

Blocks are plain maps with :facts, :rules, :checks. The caller is
responsible for signature verification and fact extraction before
calling evaluate. This separation means the engine has zero external
dependencies and can be embedded anywhere.
raw docstring

check-arityclj

(check-arity token & {:keys [authorizer]})

Finds predicates used with more than one length in token and the :authorizer — facts, rule heads and bodies, checks and policies. A pattern only matches facts of its own length, so a mismatch is almost always a typo; in a reject check or deny policy it silently never fires.

Run it on a policy set before storing it ({:blocks []} plus the authorizer), so a typo is caught before it reaches evaluation.

Returns [] when consistent, otherwise a vector of {:predicate p :arities {length [location …]}} — see datalog/arity-mismatches.

Finds predicates used with more than one length in `token` and the
`:authorizer` — facts, rule heads and bodies, checks and policies.
A pattern only matches facts of its own length, so a mismatch is
almost always a typo; in a reject check or deny policy it silently
never fires.

Run it on a policy set before storing it (`{:blocks []}` plus the
authorizer), so a typo is caught before it reaches evaluation.

Returns `[]` when consistent, otherwise a vector of
`{:predicate p :arities {length [location …]}}` — see
`datalog/arity-mismatches`.
raw docstring

evaluateclj

(evaluate token
          &
          {:keys [explain? authorizer limits arity-check]
           :or {arity-check :error}
           :as opts})

Evaluates a token (collection of fact blocks) against Datalog policy.

This is the single entry point for authorization decisions. The token must already be cryptographically verified — this function performs only logical evaluation.

Arguments:

  • token : map with :blocks — a vector of block maps, each containing: :facts — vector of fact tuples :rules — vector of rule maps (optional) :checks — vector of check maps (optional) :external-key — (optional) byte array identifying third-party signer
  • keyword args: :explain? (true or :all) — include the decision explain in result :authorizer (map) — authorizer context with: :policies — ordered allow/deny policies (first match wins). Only a matching :allow allows: with no policies (or no authorizer) the result is deny, with a {:type :no-policies} warning. To allow whatever passes the checks, use {:kind :allow :query []} :facts — additional authorizer facts :checks — additional authorizer checks :rules — additional authorizer rules :trusted-external-keys — vector of trusted third-party key bytes :limits (map) — fixpoint limits over datalog/default-limits: :max-iterations (100) and :max-facts (1000). Reaching a limit before the fixpoint denies (fail closed); unknown keys or non-positive values throw. :max-derivations (10000) only caps explain data :arity-check — :error (default), :warn or :off: whether predicates used with different lengths deny (:reason :arity-mismatch), only add :warnings, or are ignored (see check-arity)

Returns:

{:valid?  boolean
 :explain decision map (when :explain?)
 :error   {:type :limit-exceeded …} or {:type :arity-mismatch …}
          (only when a limit was reached, or on an arity mismatch)
 :warnings [{:type :arity-mismatch …} (only with :arity-check :warn)
            {:type :no-policies}]}         (when there are no policies)

The decision is binary and closed-world: whenever no policy allows — none matches, none exists, a check failed, a limit was reached — it is deny, and :reason (in the explain) and :warnings say why. The caller never gets a third outcome to interpret; one that treats a missing policy set as an error can check the warnings and throw.

Throws only on a malformed call (ex-data :stroopwafel/error): :unknown-keys (a misspelled option or authorizer key, which would otherwise be silently ignored), and invalid :limits or :arity-check.

Block scope isolation:

  • Block 0 checks see: #{0 :authorizer}
  • Block N checks see: #{0 N :authorizer}
  • Authorizer policies see: #{0 :authorizer} (+ trusted third-party indices)
Evaluates a token (collection of fact blocks) against Datalog policy.

This is the single entry point for authorization decisions. The token
must already be cryptographically verified — this function performs
only logical evaluation.

Arguments:
  - `token` : map with `:blocks` — a vector of block maps, each containing:
      `:facts`  — vector of fact tuples
      `:rules`  — vector of rule maps (optional)
      `:checks` — vector of check maps (optional)
      `:external-key` — (optional) byte array identifying third-party signer
  - keyword args:
      `:explain?`   (true or :all) — include the decision explain in result
      `:authorizer` (map)     — authorizer context with:
        `:policies` — ordered allow/deny policies (first match wins).
          Only a matching `:allow` allows: with no policies (or no
          authorizer) the result is deny, with a `{:type :no-policies}`
          warning. To allow whatever passes the checks, use
          `{:kind :allow :query []}`
        `:facts`    — additional authorizer facts
        `:checks`   — additional authorizer checks
        `:rules`    — additional authorizer rules
        `:trusted-external-keys` — vector of trusted third-party key bytes
      `:limits`     (map)     — fixpoint limits over `datalog/default-limits`:
        `:max-iterations` (100) and `:max-facts` (1000). Reaching a
        limit before the fixpoint denies (fail closed); unknown keys or
        non-positive values throw. `:max-derivations` (10000) only caps
        explain data
      `:arity-check` — `:error` (default), `:warn` or `:off`: whether
        predicates used with different lengths deny (`:reason
        :arity-mismatch`), only add `:warnings`, or are ignored (see
        `check-arity`)

Returns:
  ```clojure
  {:valid?  boolean
   :explain decision map (when :explain?)
   :error   {:type :limit-exceeded …} or {:type :arity-mismatch …}
            (only when a limit was reached, or on an arity mismatch)
   :warnings [{:type :arity-mismatch …} (only with :arity-check :warn)
              {:type :no-policies}]}         (when there are no policies)
  ```

The decision is binary and closed-world: whenever no policy allows —
none matches, none exists, a check failed, a limit was reached — it is
deny, and `:reason` (in the explain) and `:warnings` say why. The
caller never gets a third outcome to interpret; one that treats a
missing policy set as an error can check the warnings and throw.

Throws only on a malformed call (ex-data `:stroopwafel/error`):
`:unknown-keys` (a misspelled option or authorizer key, which would
otherwise be silently ignored), and invalid `:limits` or `:arity-check`.

Block scope isolation:
  - Block 0 checks see: #{0 :authorizer}
  - Block N checks see: #{0 N :authorizer}
  - Authorizer policies see: #{0 :authorizer} (+ trusted third-party indices)
raw docstring

graphclj

(graph explain-tree)

Converts an explain tree into a graph representation.

Arguments:

  • explain-tree (returned from evaluate with :explain? true)

Returns:

 {:root  node-id
  :nodes {node-id -> node}
  :edges [{:from id :to id :label kw} ...]}

Pure data transformation — no authorization logic.

Converts an explain tree into a graph representation.

Arguments:
  - `explain-tree` (returned from evaluate with :explain? true)

Returns:
 ```clojure
  {:root  node-id
   :nodes {node-id -> node}
   :edges [{:from id :to id :label kw} ...]}
 ```

Pure data transformation — no authorization logic.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close