Fork me on GitHub
#malli
<
2024-01-05
>
lwhorton02:01:02

so this is probably the wrong place to ask, but does anyone know of a malli-like lib that's implemented in native js? i've looked at options like zod , yup, joi. im not super impressed with any of them. i think ajv is probably the most data oriented, but it's tied tightly to the jsonschema spec. am i missing any relevent options i should consider before picking a dependency?

lukasz15:01:31

If I'm not mistaken, you can convert Malli schemas to JSONSchema, that could be the way to go I'm in the process of migrating my own solution where I have Prismatic Schema -> Avro -> Typescript types pipeline, and instead go with Malli -> JSONSchema to keep things simpler, but it's very early days

lwhorton17:01:44

i'm in the sad position of not being able to use any clojure / clojurescript (yet)... but i can't imagine building anything resilient without the help of prismatic/spec or malli

lukasz17:01:45

I think Zod combined with TS is what most people use, I have a somewhat narrow view into the JS world but that's I've seen in the wild

lukasz17:01:12

but yes, "types at the edges" are a necessity in Clojure, just to maintain one's sanity ;-)

ikitommi09:01:17

I remember trying out yup-ast at one point - https://github.com/WASD-Team/yup-ast

Brett Rowberry20:01:30

I want a map schema with required key :a and for both or neither :b and :c to be present. Is that possible?

Stig Brautaset20:01:16

Maybe:

[:or 
  [:map [:a int?] [:b int?] [:c int?]]
  [:map [:a int?]]]

Stig Brautaset20:01:31

It doesn't seem to translate properly to JSON Schema, mind you

Brett Rowberry20:01:49

Unfortunately no.

(malli.error/humanize 
 (malli.core/explain
  [:or
   [:map [:a int?] [:b int?] [:c int?]]
   [:map [:a int?]]]
  {:a 1
   :c 1}))
=> nil

Brett Rowberry20:01:02

This works if I’m willing to close the more minimal schema

[:or [:map [:a int?] [:b int?] [:c int?]] [:map {:closed true} [:a int?]]]

Brett Rowberry20:01:03

What’s wrong with its JSON Schema?

Stig Brautaset22:01:35

Doh! Nothing. I misread 😂

👍 1