Liking cljdoc? Tell your friends :D

pharmacist.schema

Tools for mapping, coercing, and verifying data.

Tools for mapping, coercing, and verifying data.
raw docstring

coerceclj/s

(coerce schema data k & [default])
source

coerce-dataclj/smultimethod

Coerces data according to the spec in source. The default implementation will use the schema in :pharmacist.data-source/schema and start coercion of data from the :pharmacist.schema/entity key.

Coerces `data` according to the spec in `source`. The default implementation
will use the schema in `:pharmacist.data-source/schema` and start coercion of
`data` from the `:pharmacist.schema/entity` key.
sourceraw docstring

coll-ofclj/s

(coll-of spec)

Returns what, if anything, the spec is a collection of

Returns what, if anything, the spec is a collection of
sourceraw docstring

datascript-schemaclj/s

(datascript-schema source)
(datascript-schema schema k)

Generate a Datascript schema from the Pharmacist schema. The resulting schema will include keys for uniqueness, refs, and cardinality many. Any attributes not using these features will be emitted with an empty map for documentation purposes. The resulting schema can be passed directly to Datascript.

When this function is called with a source, it uses the schema in :pharmacist.data-source/schema, and starts from the :pharmacist.schema/entity key in the schema.

Alternatively, you can call the function with a schema, and a key (which must exist in said schema).

Generate a Datascript schema from the Pharmacist schema. The resulting schema
will include keys for uniqueness, refs, and cardinality many. Any attributes
not using these features will be emitted with an empty map for documentation
purposes. The resulting schema can be passed directly to Datascript.

When this function is called with a source, it uses the schema in
`:pharmacist.data-source/schema`, and starts from the
`:pharmacist.schema/entity` key in the schema.

Alternatively, you can call the function with a schema, and a key (which must
exist in said schema).
sourceraw docstring

infer-camel-nsclj/s

(infer-camel-ns m k)

Like infer-ns, but also infers dash cased keys from their camel cased counterparts:

(require '[pharmacist.schema :as schema]
         '[clojure.spec.alpha :as s])

(def schema
  {:person/first-name {::schema/source schema/infer-camel-ns}
   ::schema/entity {::schema/spec (s/keys :req [:person/first-name])}})

(def data {:firstName "Wonderwoman"})

(schema/coerce schema data ::schema/entity)
;;=> {:person/first-name "Wonderwoman"}
Like [[infer-ns]], but also infers dash cased keys from their camel cased
  counterparts:

```clojure
(require '[pharmacist.schema :as schema]
         '[clojure.spec.alpha :as s])

(def schema
  {:person/first-name {::schema/source schema/infer-camel-ns}
   ::schema/entity {::schema/spec (s/keys :req [:person/first-name])}})

(def data {:firstName "Wonderwoman"})

(schema/coerce schema data ::schema/entity)
;;=> {:person/first-name "Wonderwoman"}
```
sourceraw docstring

infer-nsclj/s

(infer-ns m k)

Utility to help namespace keys from external sources. Pass in data and a namespaced key, and it will look up the unqualified key in the map to find the data. This can be used to extract namespaced keys from unqualified data:

(require '[pharmacist.schema :as schema]
         '[clojure.spec.alpha :as s])

(def schema
  {:person/name {::schema/source schema/infer-ns}
   ::schema/entity {::schema/spec (s/keys :req [:person/name])}})

(def data {:name "Wonderwoman"})

(schema/coerce schema data ::schema/entity)
;;=> {:person/name "Wonderwoman"}
Utility to help namespace keys from external sources. Pass in data and a
  namespaced key, and it will look up the unqualified key in the map to find the
  data. This can be used to extract namespaced keys from unqualified data:

```clojure
(require '[pharmacist.schema :as schema]
         '[clojure.spec.alpha :as s])

(def schema
  {:person/name {::schema/source schema/infer-ns}
   ::schema/entity {::schema/spec (s/keys :req [:person/name])}})

(def data {:name "Wonderwoman"})

(schema/coerce schema data ::schema/entity)
;;=> {:person/name "Wonderwoman"}
```
sourceraw docstring

specced-keysclj/s

(specced-keys spec)

Given a keyword representing a spec or an inline spec, returns all possible keys it specs, including ones from s/and and s/or.

Given a keyword representing a spec or an inline spec, returns all possible
keys it specs, including ones from s/and and s/or.
sourceraw docstring

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

× close