Liking cljdoc? Tell your friends :D

spec-tools.core


coerce

(coerce spec value transformer)
(coerce spec value transformer options)

Coerces the value using a Transformer. Returns original value for those parts of the value that can't be trasformed.

Coerces the value using a [[Transformer]]. Returns original value for
those parts of the value that can't be trasformed.
sourceraw docstring

Coercionprotocol

-coerce
(-coerce this value transformer options)
source

conform

(conform spec value)
(conform spec value transformer)

Given a spec and a value, returns the possibly destructured value or ::s/invalid

Given a spec and a value, returns the possibly destructured value
or ::s/invalid
sourceraw docstring

conform!

(conform! spec value)
(conform! spec value transformer)

Given a spec and a value, returns the possibly destructured value or fails with ex-info with :type of ::conform. ex-data also contains :problems, :spec and :value. call s/unform on the result to get the actual conformed value.

Given a spec and a value, returns the possibly destructured value
or fails with ex-info with :type of ::conform. ex-data also contains
:problems, :spec and :value. call s/unform on the result to get the
actual conformed value.
sourceraw docstring

create-spec

(create-spec {:keys [spec type form], :as m})

Creates a Spec instance from a map containing the following keys:

   :spec  the wrapped spec predicate (default to `any?`)
   :form  source code of the spec predicate, if :spec is a spec,
          :form is read with `s/form` out of it. For non-spec
          preds, spec-tools.form/resolve-form is called, if still
          not available, spec-creation will fail.
   :type  optional type for the spec. if not set, will be auto-
          resolved via spec-tools.parse/parse-spec (optional)
 :reason  reason to be added to problems with s/explain (optional)
    :gen  generator function for the spec (optional)
   :name  name of the spec (optional)

:description description of the spec (optional) :xx/yy any qualified keys can be added (optional)

Creates a Spec instance from a map containing the following keys:

       :spec  the wrapped spec predicate (default to `any?`)
       :form  source code of the spec predicate, if :spec is a spec,
              :form is read with `s/form` out of it. For non-spec
              preds, spec-tools.form/resolve-form is called, if still
              not available, spec-creation will fail.
       :type  optional type for the spec. if not set, will be auto-
              resolved via spec-tools.parse/parse-spec (optional)
     :reason  reason to be added to problems with s/explain (optional)
        :gen  generator function for the spec (optional)
       :name  name of the spec (optional)
:description  description of the spec (optional)
      :xx/yy  any qualified keys can be added (optional)
sourceraw docstring

decode

(decode spec value)
(decode spec value transformer)
(decode spec value transformer spec-transformed)

Decodes a value using a Transformer from external format to a value defined by the spec. First, calls coerce and returns the value if it's valid - otherwise, calls conform & unform. You can also provide a spec to validate the decoded value after transformation. Returns ::s/invalid if the value can't be decoded to conform the spec.

Decodes a value using a [[Transformer]] from external format to a value
defined by the spec. First, calls [[coerce]] and returns the value if it's
valid - otherwise, calls [[conform]] & [[unform]]. You can also provide a
spec to validate the decoded value after transformation. Returns `::s/invalid`
if the value can't be decoded to conform the spec.
sourceraw docstring

DynamicConforming

source

encode

(encode spec value transformer)
(encode spec value transformer spec-transformed)

Transforms a value (using a Transformer) from external format into a value defined by the spec. You can also provide a spec to validate the encoded value after transformation. On error, returns ::s/invalid.

Transforms a value (using a [[Transformer]]) from external
format into a value defined by the spec. You can also provide a
spec to validate the encoded value after transformation.
On error, returns `::s/invalid`.
sourceraw docstring

explain

(explain spec value)
(explain spec value transformer)

Like clojure.core.alpha/explain but supports transformers

Like `clojure.core.alpha/explain` but supports transformers
sourceraw docstring

explain-data

(explain-data spec value)
(explain-data spec value transformer)

Like clojure.core.alpha/explain-data but supports transformers

Like `clojure.core.alpha/explain-data` but supports transformers
sourceraw docstring

fail-on-extra-keys-transformer

Transformer that fails on extra keys in s/keys specs.

Transformer that fails on extra keys in `s/keys` specs.
sourceraw docstring

json-transformer

Transformer that transforms data between JSON and EDN.

Transformer that transforms data between JSON and EDN.
sourceraw docstring

mergemacro

(merge & forms)
source

select-spec

(select-spec spec value)

Best effort to drop recursively all extra keys out of a keys spec value.

Best effort to drop recursively all extra keys out of a keys spec value.
sourceraw docstring

specmacro

(spec pred-or-info)
(spec pred info)

Creates a Spec instance with one or two arguments:

;; using type inference (spec integer?)

;; with explicit type (spec integer? {:type :long})

;; map form (spec {:spec integer?, :type :long})

calls create-spec, see it for details.

Creates a Spec instance with one or two arguments:

;; using type inference
(spec integer?)

;; with explicit type
(spec integer? {:type :long})

;; map form
(spec {:spec integer?, :type :long})

calls `create-spec`, see it for details.
sourceraw docstring

Spec

source

spec-description

(spec-description spec)

Returns a spec description.

Returns a spec description.
sourceraw docstring

spec-name

(spec-name spec)

Returns a spec name. Like the private clojure.spec.alpha/spec-name

Returns a spec name. Like the private clojure.spec.alpha/spec-name
sourceraw docstring

spec?

(spec? x)
source

string-transformer

Transformer that transforms data between Strings and EDN.

Transformer that transforms data between Strings and EDN.
sourceraw docstring

strip-extra-keys-transformer

Transformer that drop extra keys from s/keys specs.

Transformer that drop extra keys from `s/keys` specs.
sourceraw docstring

strip-extra-values-transformer

Transformer that drop extra values from s/tuple specs.

Transformer that drop extra values from `s/tuple` specs.
sourceraw docstring

Transformerprotocol

-decoder
(-decoder this spec value)
-encoder
(-encoder this spec value)
-name
(-name this)
-options
(-options this)
source

type-transformer

(type-transformer & options-or-transformers)

Returns a Transformer instance out of options map or Transformer instances. Available options:

Key Description
:name Name of the transformer
:encoders Map of type type -> transform
:decoders Map of type type -> transform
:default-encoder Default transform for encoding
:default-decoder Default transform for decoding

Example of a JSON type-transformer:

(require '[spec-tools.core :as st])
(require '[spec-tools.transform :as stt])

(def json-transformer
  (type-transformer
    {:name :json
     :decoders stt/json-type-decoders
     :encoders stt/json-type-encoders
     :default-encoder stt/any->any}))

Composed Strict JSON Transformer:

(def strict-json-transformer
  (st/type-transformer
    st/json-transformer
    st/strip-extra-keys-transformer
    st/strip-extra-values-transformer))
Returns a Transformer instance out of options map or Transformer instances.
Available options:

| Key                | Description
|--------------------|-----------------
| `:name`            | Name of the transformer
| `:encoders`        | Map of type `type -> transform`
| `:decoders`        | Map of type `type -> transform`
| `:default-encoder` | Default `transform` for encoding
| `:default-decoder` | Default `transform` for decoding

Example of a JSON type-transformer:

```clojure
(require '[spec-tools.core :as st])
(require '[spec-tools.transform :as stt])

(def json-transformer
  (type-transformer
    {:name :json
     :decoders stt/json-type-decoders
     :encoders stt/json-type-encoders
     :default-encoder stt/any->any}))
```

Composed Strict JSON Transformer:

```clojure
(def strict-json-transformer
  (st/type-transformer
    st/json-transformer
    st/strip-extra-keys-transformer
    st/strip-extra-values-transformer))
```
sourceraw docstring

walkmultimethod

source

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close