that look ok @jeroenvandijk?
@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
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.
Does Malli have an equivalent of (clojure.spec.alpha/map-of string? string)
.e.g {"any-string-key" "any-string-value"}
?
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})
[:map-of string? string?]
ah ๐
Thanks
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
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
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.
not sure if there is an issue of that, should be.
@ikitommi So far the lazyness works really nice. Iโll let you know when Iโm done
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"
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))
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.
next step would be to make clj-kondo use malli somehow, so we would get static inspection.
and the next would be to have auto-complete via lsp.
(no idea how to do the last, clj-kondo should be fun to try)
Sounds awesome!
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
ah wait i think i see some pointers
@ikitommi is this related to what you showed on ClojureD? I'm not sure what you mean by clj-kondo using malli