Say I have the following specs:
(s/def :person/age number?)
(s/def :person/name string?)
(s/def ::person (s/keys :req [:person/name :person/age]))
Then I fetch an entity from Datomic:
(def person-entity (d/entity (d/db conn) [:person/name "Mr entity"]))
If I try to check conformance with the spec it fails because entities are not maps:
(s/explain ::person person-entity)
val: #:db{:id 17592186069950} fails spec: :some-ns/person predicate: map?
My app has functions that take entities as arguments and would like to avoid having to reify entities to maps everywhere just to get spec instrumentation to work in development.
How should I go about validating entities through spec?
{:person/name "Mr. Entity"}
, which does not validate against(s/keys :req [::name ::age])
unless those definitions happen to be in(ns person)
. But that forces you to define a bunch of top level package namespaces, which doesn't seem reasonable. – Manhour