invariant.core.protocols

Base Functionality for Invariants

->invariant-error

(->invariant-error name path state values)(->invariant-error name path state values error-context)

Create a new invariant verification error, a map with the following keys:

  • :invariant/name: the name of the failed invariant,
  • :invariant/state: the state of the invariant when failing,
  • :invariant/path: the path the invariant failed at,
  • :invariant/values: the values that could not be verified,
  • :invariant/error-context: an arbitrary, invariant-dependent error context map.

Invariant

protocol

members

run-invariant

(run-invariant invariant path state value)

Return a map of:

  • :path: a descriptive path to the verified data,
  • :data: a seq of verified elements,
  • :state: the current invariant state,
  • :errors: verification errors encountered.

invariant-failed

(invariant-failed name path state value)(invariant-failed name path state value error-context)

Create a result for run-invariant indicating failed resolution using a single relevant value.

invariant-failed*

(invariant-failed* path state value errors)

Create a result for run-invariant using a single relevant value and a seq of errors.

invariant-holds

(invariant-holds path state value)

Create a result for run-invariant indicating successful resolution.

merge-error-context

(merge-error-context result error-context)

Merge the given error context into each error of result.

merge-results

(merge-results result1 result2)

Merge the results of two invocations of run-invariant.