malli

https://github.com/metosin/malli :malli:
ikitommi 2020-09-04T08:46:10.078200Z

ikitommi 2020-09-04T08:47:01.079200Z

that look ok @jeroenvandijk?

2020-09-04T08:48:17.080Z

@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

ikitommi 2020-09-04T08:55:09.082Z

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.

2020-09-04T16:38:05.083200Z

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

2020-09-04T16:51:29.083800Z

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})

ikitommi 2020-09-04T17:03:11.084Z

[:map-of string? string?]

2020-09-04T17:04:39.084200Z

ah ๐Ÿ™‚

2020-09-04T17:04:46.084400Z

Thanks

2020-09-04T17:15:23.084600Z

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

2020-09-04T17:39:19.085900Z

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

ikitommi 2020-09-04T18:04:50.086Z

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.

๐Ÿ‘ 1
ikitommi 2020-09-04T18:06:34.086200Z

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

2020-09-04T18:23:50.087400Z

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

2020-09-04T18:41:46.088600Z

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"

2020-09-04T18:43:12.089400Z

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))

ikitommi 2020-09-04T19:22:43.092800Z

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.

ikitommi 2020-09-04T19:24:41.094700Z

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

ikitommi 2020-09-04T19:25:21.095800Z

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

ikitommi 2020-09-04T19:26:20.097200Z

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

2020-09-04T19:36:44.097600Z

Sounds awesome!

2020-09-04T19:39:01.097800Z

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

2020-09-04T19:47:09.098Z

ah wait i think i see some pointers

borkdude 2020-09-04T20:01:42.098500Z

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