schema.spec.core

Protocol and preliminaries for Schema 'specs', which are a common language
for schemas to use to express their structure.

+no-precondition+

CoreSpec

protocol

Specs are a common language for Schemas to express their structure.
These two use-cases aren't privileged, just the two that are considered core
to being a Spec.

members

checker

(checker this params)
Create a function that takes [data], and either returns a walked version of data
(by default, usually just data), or a utils/ErrorContainer containing value that looks
like the 'bad' parts of data with ValidationErrors at the leaves describing the failures.

params is a map specifying:
 - :subschema-checker - a function for checking subschemas
 - :returned-walked? - a boolean specifying whether to return a walked version of the data
   (otherwise, nil is returned which increases performance)
 - :cache - a map structure from schema to checker, which speeds up checker creation
   when the same subschema appears multiple times, and also facilitates handling
   recursive schemas.

subschemas

(subschemas this)
List all subschemas

precondition

(precondition s p err-f)
Helper for making preconditions.
Takes a schema, predicate p, and error function err-f.
If the datum passes the predicate, returns nil.
Otherwise, returns a validation error with description (err-f datum-description),
where datum-description is a (short) printable stand-in for the datum.

run-checker

(run-checker f return-walked? s)
A helper to start a checking run, by setting the appropriate params.
For examples, see schema.core/checker or schema.coerce/coercer.

simple-precondition

macro

(simple-precondition s f-sym)
A simple precondition where f-sym names a predicate (e.g. (simple-precondition s map?))

sub-checker

(sub-checker {:keys [schema error-wrap]} {:keys [subschema-checker cache], :as params})
Should be called recursively on each subschema in the 'checker' method of a spec.
Handles caching and error wrapping behavior.

with-cache

(with-cache cache cache-key wrap-recursive-delay result-fn)