Fork me on GitHub
#malli
<
2020-07-09
>
ikitommi07:07:43

re-implemented the schema visitor using walker: m/accept is now a postwalk and and there is new m/find-first to do lazy scanning for schemas. Though of doing a prewalk too, but coudn’t find any valid use case for such and would be more complex for schema extenders to add support for it. Not sure how useful the m/find-first is and should merge this: https://github.com/metosin/malli/pull/216

ikitommi07:07:15

should the m/accept be just m/walk in the future? or m/post-walk?

ikitommi09:07:05

(deftest find-first-test
  (let [schema [:map
                [:x int?]
                [:y [:vector [:tuple
                              [:maybe int?]
                              [:or [:and {:salaisuus "turvassa"} boolean?] int?]
                              [:schema {:salaisuus "vaarassa"} false?]]]]
                [:z [:string {:salaisuus "piilossa"}]]]]

    (let [walked-properties (atom [])]
      (is (= "turvassa" (m/find-first
                          schema
                          (fn [s _in _options]
                            (some->> s m/properties (swap! walked-properties conj))
                            (some-> s m/properties :salaisuus)))))
      (is (= [{:salaisuus "turvassa"}] @walked-properties)))

    (let [walked-properties (atom [])]
      (is (= "vaarassa" (m/find-first
                          schema
                          (fn [s _in _options]
                            (some->> s m/properties (swap! walked-properties conj))
                            (some-> s m/properties :salaisuus #{"vaarassa"})))))
      (is (= [{:salaisuus "turvassa"}
              {:salaisuus "vaarassa"}] @walked-properties)))))

alpox09:07:24

Hi all! Is there a possibility to merge definitions declaratively - for example in an edn definition given that the definitions to merge are defined in a registry?

alpox09:07:17

I see I can do

[:and
 [:ref :test/object]
 [:ref :test/annotated]
 [:map ....]]
but sadly this would test for all to be true rather than that later definitions override definitions from the former. Basically, I'm asking if there is something like mu/merge in a declarative way

👍 3
ikitommi12:07:32

@alpox nothing just now, but sounds like a good idea. Could you write an issue of that?

euccastro14:07:07

what's the idiomatic way to specify a nonempty string in a schema? should I actually use a custom registry as in the README?

euccastro14:07:43

currently I'm doing this

(def nonempty-string
  [:and
   string?
   [:fn {:error/message "should be nonempty string"}
    (fn [x] (pos? (count x)))]])

euccastro14:07:05

one minor problem with that is that malli/explain gives me two error messages: "should be string" and "should be nonempty string". I tried to set the :error/message in the :and instead to get only one error, but that didn't work

euccastro14:07:48

(I'm using the malli version that reitit 0.5.2 requires, i.e. 0.0.1-20200525.162645-15, if that matters)

euccastro14:07:49

I'm happy to upgrade to any version that is compatible with reitit 0.5.2

ikitommi14:07:12

@U65FN6WL9 [:string {:min 1}], will need to release new version to work with reitit

jkent15:07:10

@ikitommi is there any chance you can release a new version of reitit with the latest malli?

euccastro17:07:10

another option for early adopters would be to release cutting-edge versions of malli under a separate namespace and artifact id (e.g., malli.pre-alpha) so we can use that for our own code without fear of breaking reitit. that would also reduce the pressure to update reitit unless new malli functionality is actually needed there

euccastro17:07:37

please ignore this if it sounds like too much of a hassle 🙂