Fork me on GitHub
#malli
<
2021-09-06
>
emccue04:09:53

remembering typescript has https://github.com/DefinitelyTyped/DefinitelyTyped and wondering if it would be sensible to do something similar for clj* libraries and malli

emccue05:09:53

Motivating example for me most recently is datomic's api - it gives annoying and obtuse errors if you pass bad data and spec'ing inputs at dev time would be helpful

emccue05:09:05

(alter-meta!
  #'d/transact
  assoc
  :malli/schema
  [:=>
   [:cat some? [:map [:tx-data some?]]]
   [:map
    [:db-before any?]
    [:db-after any?]
    [:tx-data  any?]
    [:tempids any?]]])

emccue05:09:02

idk what the best approach is - maybe artificially associate with a namespace at first instead of the metadata?

emccue05:09:20

(defn register-possibly-nonexistant-schema
  [var-path schema]
  (m/-register-function-schema! (symbol (namespace var-path))
                                (symbol (name var-path))
                                schema
                                nil))

(register-possibly-nonexistant-schema
  'datomic.client.api/transact
  [:=>
   [:cat some? [:map [:tx-data some?]]]
   [:map
    [:db-before any?]
    [:db-after any?]
    [:tx-data  any?]
    [:tempids any?]]])

emccue05:09:38

or maybe just ignore it and let library authors do it themselves

emccue05:09:50

and fight the inevitable war with whatever is finally christened spec 2

emccue05:09:17

or maybe the library has its own registry you can select from and merge into your own / the global registry

lsenjov05:09:47

Pick a top level namespaces that does all the (m/=> ...) declarations, and they can include it themselves if they feel so inclined?

☝️ 2
Noah Bogart17:09:43

Clj-kondo has this for linting. Maybe malli could adopt a similar pattern?

ikitommi17:09:05

that would be interesting. One of my goals with clojurists-together is to get a robust schema inferrer: for runtime for inferring from schemas from samples, but could be used to pull out schemas from tests (annotate functions in dev-mode to infer input & output) schemas. Not a silver bullet, but would be “for free”. Manually writing functios schmas is always better, but also, a lot of work.

🔥 2