malli

https://github.com/metosin/malli :malli:
ikitommi 2021-03-13T07:44:54.347Z

not at the moment. issue welcome.

ikitommi 2021-03-13T07:45:31.347900Z

::m/default for :multi merged in master:

(def valid?
  (m/validator
    [:multi {:dispatch :type}
     ["object" [:map-of :keyword :string]]
     [::m/default :string]]))

(valid? {:type "object", :key "1", :value "100"})
; => true

(valid? "SUCCESS!")
; => true

(valid? :failure)
; => false

💯 1
ikitommi 2021-03-13T07:50:04.348600Z

Maybe the same could be used for extra keys in maps? (https://github.com/metosin/malli/issues/43)

borkdude 2021-03-13T09:53:20.350800Z

@ikitommi I was trying (for fun) to write a core.match like thing with malli. So {:a ?x :b 1} would match on {:a 2 :b 1} and parsing would give you back {?x 1}. This is currently a bit difficult since you cannot change how keys are named in the parsed output from map schemas, can you?

borkdude 2021-03-13T09:54:28.351600Z

So I would generate a schema like {:b [:= 1] :a :any} but then the parsed output loses the name ?x

borkdude 2021-03-13T10:07:10.352400Z

Can I influence how things get parsed using an extra predicate similar to s/and in spec?

(m/parse [:map [:a [:and :any
                         [:fn (fn [x]
                                ['x? x])]]]]
              {:a 1})

ikitommi 2021-03-13T10:13:00.357200Z

not atm, parsing could have it's own property key for this, e.g. [:map {:parse ...} ...]. Internally, could be interceptors, so one can do easily pre, post & schema-based parsing with that.

ikitommi 2021-03-13T10:13:46.358700Z

We discussed with @nilern about combining internally parsing, explain and transform. They are now mostly (optimized) duplicates of each other.

ikitommi 2021-03-13T10:15:06.360600Z

map keys -> could done with same mechanism. Add custom parse tags to keys as properties and hook a post-parse fn to rename the keys. Or do, whatever.

ikitommi 2021-03-13T11:04:09.365100Z

ported the plumatic-style inline schemas for 0.3.0, it kinda works, but no tests and not happy with the original (string-based) error reporting. renamed to ns to malli.experimental.schema as it might not be part of the malli core library. any thoughts on this? add tests, cleanup and ship as experimental add-on?

👍 2
vemv 2021-03-14T14:18:29.384800Z

Replied in https://github.com/metosin/malli/issues/125 . Btw I hope I'm not pestering too much - I simply try to make an educated attempt at improving perceived problems (which can last long - for example I use Schema at work and it kinda hurts to use an outdated tech that turned out to not be the best bet)

ikitommi 2021-03-13T11:04:40.365500Z

https://github.com/metosin/malli/pull/305

ikitommi 2021-03-13T11:06:42.365900Z

the defn now emits a function schema into malli function registry and it can be configured to validate always, never or based on a dynamic var - at runtime.

2021-03-13T13:03:33.367500Z

what is the validator i can use for 'any collection, no matter the type' ? i don't care whether it's a sequence or vector or set, just that it's a collection. what can i use for this? i wasn't able to find it

ikitommi 2021-03-13T14:26:31.368100Z

@lmergen maybe coll?

2021-03-13T14:27:23.368700Z

i can use that like [:coll pos-int?] ?

2021-03-13T14:30:28.370500Z

trying to figure out the best way to do this 🙂

ikitommi 2021-03-13T14:31:03.372700Z

sadly, it's just the core predicate, so no child type checking. There is no :coll atm. Would be a oneliner to add

2021-03-13T14:32:12.373300Z

is there a specific reason why this is not in malli itself? as in, if i would send a PR to add this, would that be useful?

ikitommi 2021-03-13T14:32:53.373500Z

no-one has asked, PR welcome (tests included)!

2021-03-13T14:33:08.373700Z

of course 👍

ikitommi 2021-03-13T14:33:30.373900Z

it spans to generator, json schema, human errors etc. But, good examples :)

2021-03-13T14:33:30.374Z

thanks, i'll see what i can do

👍 1
2021-03-13T14:33:42.374400Z

yes it touches a lot of surface

juhoteperi 2021-03-13T14:44:37.375400Z

coll? also matches maps, that has some effects on JSON-Schema implementation at least

☝️ 1
ikitommi 2021-03-13T15:19:38.378400Z

good point. I guess there is not a predicate for non-map collection.

nilern 2021-03-13T15:24:01.379900Z

I imagine maps also having keys can lead to all sorts of confusion when implementing [:coll pos-int?]

nilern 2021-03-13T15:24:21.380300Z

What about :sequential?

nilern 2021-03-13T15:25:58.380600Z

Oh that does not take sets

nilern 2021-03-13T15:31:42.382500Z

Can always do [:or [:sequential pos-int?] [:set pos-int?]]

nilern 2021-03-13T15:33:29.383600Z

That does not support seqs though... and now I see nothing else does either.

nilern 2021-03-13T15:37:16.384Z

Made some issues about that https://github.com/metosin/malli/issues/393 https://github.com/metosin/malli/issues/394