This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-13
Channels
- # announcements (1)
- # babashka (41)
- # beginners (194)
- # calva (14)
- # chlorine-clover (2)
- # cider (32)
- # circleci (9)
- # cljsrn (10)
- # clojure (110)
- # clojure-australia (1)
- # clojure-berlin (2)
- # clojure-dev (39)
- # clojure-europe (42)
- # clojure-france (3)
- # clojure-nl (19)
- # clojure-spec (22)
- # clojure-uk (23)
- # clojurescript (21)
- # conjure (41)
- # datomic (33)
- # depstar (16)
- # duct (46)
- # events (1)
- # fulcro (17)
- # graphql (14)
- # jobs (6)
- # jobs-discuss (9)
- # leiningen (6)
- # malli (29)
- # off-topic (21)
- # pathom (7)
- # portal (1)
- # rdf (81)
- # re-frame (3)
- # reagent (12)
- # reitit (2)
- # remote-jobs (1)
- # rum (1)
- # shadow-cljs (60)
- # specter (1)
- # sql (13)
- # tools-deps (23)
- # vrac (1)
- # yada (19)
https://github.com/metosin/malli/pull/278, added :key
and :defaults
to mt/default-value-transformer
to make it easier to create empty/default values with it:
(m/decode
[:map
[:user [:map
[:name :string]
[:description {:ui/default "-"} :string]]]]
nil
(mt/default-value-transformer
{:key :ui/default
:defaults {:map (constantly {})
:string (constantly "")}}))
; => {:user {:name "", :description "-"}}
the values in :defaults
can access the Schema instance, so can use any information from it to create the default, e.g. schema -> default
function.
Is it possible to override the default error message for :re
?
I would like it to be general
Like, for all regexp errors I apply a custom message
not a good way to do that, but one can override the :errors
from malli.error
like this:
(-> #"\d+"
(m/explain "kikka")
(me/humanize {:errors {:re {:error/message "not a number"}}}))
; => ["not a number"]
My goal is to have an error message like this: "Value: %s does not comply with regexp: %s" 🙂
maybe:
(defn regex-error [{:keys [value schema]} _]
(str "Value: " value " does not comply with regexp: " (first (m/children schema))))
(-> #"\d+"
(m/explain "kikka")
(me/humanize {:errors {:re {:error/fn regex-error}}}))
; => ["Value: kikka does not comply with regexp: \\d+"]
I'll check it out. Thanks for the inspiration @ikitommi
(ns data.recursive-case
(:require [malli.util :as mu]))
(def asset
[:map
[:asset/id string?]
[:asset/status [:enum :initialized :accepted :active :revoked :failed]]
[:asset/asset {:optional true} asset]])
(def org-asset
(mu/merge
asset
[:map
[:asset/org :org]]))
(def user-asset
(mu/merge
asset
[:map
[:asset/user :user]]))
Execution error (ExceptionInfo) at malli.core/-fail! (core.cljc:79).
:malli.core/invalid-schema {:schema #object[clojure.lang.Var$Unbound 0x4bcbe824 "Unbound: #'data.recursive-case/asset"]}
pretty sure I've misunderstood something to do with registries so would appreciate if anyone can suggest what's up this
You might need to add asset
into a registry which you actually want to use it in. e.g. something like this:
{::asset
[:map
[:asset/id string?]
[:asset/status [:enum :initialized :accepted :active :revoked :failed]]
[:asset/asset {:optional true} [:ref ::asset]]]}
https://github.com/metosin/malli#recursive-schemas@ikitommi I have been bitten by round-trip java.time.Instant -> string -> malli -> #inst. The problem manifests in java9+ because of increased precision from miliseconds to microseconds. I noticed there is a bigger plan for time handling code but in the meantime I patched the string->date
transformer. Should I do a PR for that? See https://github.com/metosin/malli/compare/master...katox:timestamp-frac-precision
Seems like a good idea (as long as the code still works on Java8 to the extent that it can work)
i have JSON data that has entries like "Start":new Date(1413147600000) . clojure JSON parsers (at least Cheshire and Jsonista) choke on this. i wonder if it's possible to use malli.core/decode with the :enter interceptor to parse this and transform it to "Start": 1413147600000 ? my first attempt produces an exception
Schema inference is awesome going to save me a tone of time. Before I start reinventing a wheel, is anybody working on transforming malli schema to Datomic schema?
Looks to be pretty straightforward. I've done this with spec before. There were two headaches there, one being the lack of a public data representation for specs, second being opaque predicates. In the latter case we used test.check to generate examples and tried to infer from that. I think you do the same thing here, but leveraging malli's inference.