This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-16
Channels
- # announcements (3)
- # babashka (48)
- # beginners (35)
- # calva (3)
- # chlorine-clover (5)
- # clj-kondo (9)
- # cljdoc (20)
- # cljsrn (1)
- # clojure (55)
- # clojure-europe (33)
- # clojure-nl (3)
- # clojure-norway (6)
- # clojure-spec (7)
- # clojure-uk (27)
- # clojurescript (95)
- # closh (1)
- # conjure (1)
- # cursive (16)
- # datomic (30)
- # emacs (7)
- # honeysql (1)
- # hugsql (2)
- # introduce-yourself (2)
- # jobs (1)
- # lsp (30)
- # malli (22)
- # nbb (11)
- # news-and-articles (1)
- # off-topic (8)
- # pathom (21)
- # polylith (41)
- # portal (4)
- # practicalli (4)
- # protojure (1)
- # re-frame (14)
- # releases (1)
- # restql (1)
- # reveal (24)
- # sci (1)
- # sql (21)
- # vim (11)
- # xtdb (33)
I'm working with the malli schema functions (the new dev error reporting is nice!) and I seem to be at a crossroads:
1. If I choose to use m/=>
at the top-level:
a. I need to an explicit dependency on malli (not generally a problem with applications, but this is probably a no-go for libraries)
b. I cannot use non-standard registry schemas, since it is evaled at compile time.
c. I think even if I could force some preload logic to make sure my global malli registry is updated before other namespaces are loaded, this is both prone to errors and probably would still not work with external tools that work per-file (clj-kondo, etc)
2. If I choose to use :malli/schema
metadata:
a. I am free to include it optionally without directly requiring malli
b. I can use non-standard registry schemas
c. The malli.dev/start!
does not pick up var changes (need to force a refresh)
d. The metadata approach sometimes makes the function feel "verbose". This is a obviously a subjective feeling, but if the specs are verbose and the function body is short, sometimes the separate m/=>
looks nicer.
Because of the problems with (1), I'm thinking of still focusing on (2). I can workaround (2c) and perhaps (2d) can be mitigated in certain cases with a (def foo-schema [:=> ...])
and then using (defn foo {:malli/schema #'foo-schema} ..)
?
Posting these observations, in hopes that someone can set me straight on my misunderstanding; or perhaps suggest a better approach? :)
• 1b&c -> this should be resolved somehow, please write an issue • 2c -> can be fixed (look up for var changes automatically) • d -> true that what might help if malli could pick up the function schemas from the actual functions behind the vars. it would allow one to say:
(defn kikka [])
;; just clojure
(defn => [v schema]
(alter-var-root v vary-meta assoc :malli/schema schema))
;; add a function schemas without deps to malli
(=> #'kikka [:=> :cat :any])
;; reading from function
(-> kikka meta :malli/schema) ; => [:=> :cat :any]
• 1b&c -> this should be resolved somehow, please write an issue • 2c -> can be fixed (look up for var changes automatically) • d -> true that what might help if malli could pick up the function schemas from the actual functions behind the vars. it would allow one to say:
(defn kikka [])
;; just clojure
(defn => [v schema]
(alter-var-root v vary-meta assoc :malli/schema schema))
;; add a function schemas without deps to malli
(=> #'kikka [:=> :cat :any])
;; reading from function
(-> kikka meta :malli/schema) ; => [:=> :cat :any]
Hello there
I'm trying to create a parser for converting malli's schemas to DTS files (typescript's type definitions file). One of the situations I'm running into is reading malli's schemas correctly, as they're plain data structures with semantic meaning, so I have to check for some options maps when parsing :map or even cases like https://github.com/metosin/malli#qualified-keys-in-a-map. I was thinking of writing a https://github.com/metosin/malli#parsing-values for helping me out with that, but maybe it already exists? Or is there an easier way?
Sounds great, looking forward to this! You can as m/children
and m/properties
from a Schema instance. The first one returns the parsed enty-tuples [key properties value]
if that helps.
m/children
is exactly what I was looking for! Thanks :D
Will monitor this - we have TypeScript as frontend and indeed sharing the API specs would be super cool 🙂
Btw, the JSON Schema converter is a good example of generic transformer of malli->xyz, https://github.com/metosin/malli/blob/master/src/malli/json_schema.cljc
@U4U6BDQTE how far did you get with this project? Do you need/would you accept any help? 😄
hey there
at the company I work for we started testing it in production actually
the api is not stable
the code is not pretty
but it works for us haha
go check it out at flowyoumoney/malli-ts
we didn't setup a collaboration structure just yet, but I think help is welcome!
nice that looks great! I think my company would greatly benefit from it and we'll try to give back 😄