Fork me on GitHub
#malli
<
2023-11-30
>
Patrick Delaney08:11:36

I was reading through the malli docs, and tried the following:

user=> (require '[malli.provider :as mp] '[malli.transform :as mt])
nil
user=> (mp/provide
  #_=>  [{:id "caa71a26-5fe1-11ec-bf63-0242ac130002"
  #_=>    :time "2021-01-01T00:00:00Z"}
  #_=>   {:id "8aadbf5e-5fe3-11ec-bf63-0242ac130002"
  #_=>    :time "2022-01-01T00:00:00Z"}]
  #_=>  {::mp/value-decoders {'string? {:uuid mt/-string->uuid
  #_=>                                  'inst? mt/-string->date}}})
[:map [:id :string] [:time :string]]
but was expecting:
; => [:map [:id :uuid] [:time inst?]
is there another example of using malli.provider/value-decoders or did the conventions for using it change? I'm on 0.13.0

ikitommi08:11:01

hi. the docs are not up-to-date, could you PR a fix here? what has changed: • provider creates real schemas instead of predicates, e.g. :string over string? • this applies to the ::mp/value-decoders so, this is the new correct:

(mp/provide
 [{:id "caa71a26-5fe1-11ec-bf63-0242ac130002"
   :time "2021-01-01T00:00:00Z"}
  {:id "8aadbf5e-5fe3-11ec-bf63-0242ac130002"
   :time "2022-01-01T00:00:00Z"}]
 {::mp/value-decoders {:string {:uuid mt/-string->uuid
                                'inst? mt/-string->date}}})
; => [:map [:id :uuid] [:time inst?]]

Patrick Delaney08:11:36

thank you for your help! I'll make a PR.

twashing17:11:57

I’m getting an OutOfMemoryError when calling malli.core/validate... where the return type is a Malli SchemaObject. Both of these calls with the below input. I did notice someone asking a https://clojurians.slack.com/archives/CLDK6MFMK/p1617265988295000?thread_ts=1617177945.267200&cid=CLDK6MFMK. But there doesn’t seem to be a resolution. Is there something else I need to know about fn validation?

(m/explain =>fn-schema my-fn)
(m/validate =>fn-schema my-fn {:gen/max 1})

(def SchemaMap
  [:map
   [:foo/a string?]
   [:foo/b inst?]])

(def SchemaObject
  (m/schema
   [:schema {:registry custom-registry}
    ::thing]
   {:registry default-registry}))

;; Works
(def =>fn-schema
  (m/schema
   [:=> [:cat SchemaObject string? inst?] string?]
   {::m/function-checker mg/function-checker}))

;; Fails
(def =>fn-schema
  (m/schema
   [:=> [:cat SchemaObject string? inst?] SchemaMap]
   {::m/function-checker mg/function-checker}))

;; hangs until surfacing... Execution error (OutOfMemoryError) at clojure.test.check.generators/gen-tuple$fn (generators.cljc:89).

dvingo22:11:22

is ::thing a recursive schema? https://github.com/metosin/malli/tree/master#recursive-schemas > Without the :ref keyword, malli eagerly expands the schema until a stack overflow error is thrown:

twashing20:12:43

@U051V5LLP Thanks for replying. ::thing is a nested map, where some of the leaves reference other entries in the custom-registry . I combed through custom-registry and I don’t see anything pointing back to ::thing. Ie no circular references. But is there a tool or flag that might detect that?

Patrick Delaney23:11:03

I got excited when I saw malli.provider because I loved F# type providers, and I'm always struggling to give other readers of code concrete examples of data. It's not really a technical question I was just wondering if anybody had done anything with malli.provider that they felt particularly proud of or thought clever to share. Looking to grok whats out there

dvingo23:11:02

working with a ~8 year old datomic database which doesn't have great docs of the shape of entities. Picked a few db.unique identity attributes and queried for a large sample of them using (pull [*]) to get all first-level attributes on those entities and then pass the result to malli.provider - very useful

💯 1
Martín Varela06:12:58

Similar thing, but off a Cassandra data store. I used a bunch of query results to start off my specs.

💯 1
ikitommi15:12:42

Root Reason for creating malli providers: 7y of MongoDB data accumulation, with evolutionary typos, key renames & all: with malli, got full timestamped schema evolution 💪