Fork me on GitHub
#malli
<
2020-09-04
>
jeroenvandijk08:09:17

@ikitommi it looks perfect! I need to wrap my head around it, but the demo looks exactly what I want. I’ll try to convert a spec project today and give some feedback

ikitommi08:09:09

great! changes in the core are in this commit: https://github.com/metosin/malli/pull/252/commits/3a5c7f35141e32eea3b374b6a81e706377a44d26, need to add polish the code before merging in, most likely this week.

jeroenvandijk16:09:05

Does Malli have an equivalent of (clojure.spec.alpha/map-of string? string) .e.g {"any-string-key" "any-string-value"} ?

jeroenvandijk16:09:29

As an alternative this seems to work:

(require '[malli.core :as m])

(defn map-of [k v]
  (clojure.walk/postwalk-replace
   {::k k
    ::v v}
   '[:fn (fn [x] (and (map? x)
                     (every? (fn [[k v]]
                               (::k k)
                               (::v v))
                             x)))]))

(m/validate (map-of 'string? 'string?) {:a 1})

ikitommi17:09:11

[:map-of string? string?]

jeroenvandijk17:09:23

Would it make sense to add validation on the schema definition? e.g. i did this in a nested schema

(m/validate '[:map string? string?] {})
I had no idea of course and I was looking for the place that was causing this message
java.lang.UnsupportedOperationException: count not supported on this type: Symbol

ikitommi18:09:50

IntoSchema protocol will have a methods that describe both children and properties as malli schemas. After that, malli validates the malli schemas :) That requires the regex-schemas, which is the next thing. So, yes, but not yet.

👍 3
ikitommi18:09:34

not sure if there is an issue of that, should be.

jeroenvandijk17:09:19

I was thinking of trying the non-lazy approach first, but I think the lazy version will be easier to debug 😅 I can print what faulty schema is being loaded just before it crashes

jeroenvandijk18:09:50

@ikitommi So far the lazyness works really nice. I’ll let you know when I’m done

jeroenvandijk18:09:46

Is it possible to somehow add the spellcheck on the dispatch as well? Would be super fancy 🙂 E.g. when I type

"AWS::AppSync::ApiK" ==> you misspelled "AWS::AppSync::ApiKey"

jeroenvandijk18:09:12

I’ve added a try/catch around the schema loading. Makes it much easier to debug a wrong definition:

(fn [type registry]
    (let [definition (lookup-fn type)
          schema (when definition
                   (try
                     (m/schema definition {:registry registry})
                     (catch Exception e

                       (throw (ex-info (str "Error while loading " type ": " (pr-str (ex-message e))) {:definition definition})))
                     ))]
      (println "loaded" (pr-str type))
      schema))

ikitommi19:09:43

should be possible. The spell checking reads the explain output. Just need to ensure :multi emits error on invalid dispatch key that the spell checker understands. Internally, :map and :multi both use the entry-syntax, so might be just few loc.

jeroenvandijk19:09:01

As far as I can see the spelling feature is focussed on the misspelling of keys and not of values. I probably missing something though. I was missing this spelling on values also when I was spec with expound and spell-check. Maybe it’s a different kind of problem

jeroenvandijk19:09:09

ah wait i think i see some pointers

ikitommi19:09:41

next step would be to make clj-kondo use malli somehow, so we would get static inspection.

ikitommi19:09:21

and the next would be to have auto-complete via lsp.

rutledgepaulv02:09:15

I was wondering if lsp integration was in the cards 🙂 I would love to be able to write a malli schema and from it receive strong editor support for data that needs to conform to that schema (like some tools provide for xsd).

ikitommi19:09:20

(no idea how to do the last, clj-kondo should be fun to try)

jeroenvandijk19:09:44

Sounds awesome!

borkdude20:09:42

@ikitommi is this related to what you showed on ClojureD? I'm not sure what you mean by clj-kondo using malli