diff --git a/.github/workflows/clojure.yml b/.github/workflows/clojure.yml index 872287aeb..9fc5e53ad 100644 --- a/.github/workflows/clojure.yml +++ b/.github/workflows/clojure.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: # Supported Java versions: LTS releases and latest - jdk: [8, 11, 17, 21] + jdk: [11, 17, 21] clojure: [11] name: Clojure ${{ matrix.clojure }} (Java ${{ matrix.jdk }}) @@ -26,7 +26,7 @@ jobs: with: distribution: zulu java-version: ${{ matrix.jdk }} - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: | ~/.m2/repository @@ -56,7 +56,7 @@ jobs: with: distribution: zulu java-version: 11 - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: | ~/.m2/repository @@ -88,7 +88,7 @@ jobs: with: distribution: zulu java-version: 11 - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: | ~/.m2/repository diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d311144e..20610b023 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,18 @@ We use [Break Versioning][breakver]. The version numbers follow a `.` takes optional 3rd child, the guard schema validating vector of arguments and return value `[args ret]`. See [Function Guards](docs/function-schemas.md#function-guards) for more details. Fixes [#764](https://github.com/metosin/malli/issues/764) and [#764](https://github.com/metosin/malli/issues/764). @@ -561,14 +573,14 @@ No need to play with Compiler options or JVM properties to swap the default regi ;; look ma, just works (mr/set-default-registry! - (mr/composite-registry - (m/default-schemas) - (mu/schemas))) + (mr/composite-registry + (m/default-schemas) + (mu/schemas))) (mg/generate - [:merge - [:map [:x :int]] - [:map [:y :int]]]) + [:merge + [:map [:x :int]] + [:map [:y :int]]]) ; => {:x 0, :y 92} ``` diff --git a/README.md b/README.md index eb63a5e1a..38e4be3cf 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ So, we decided to spin out our own library, which would do all the things we fee [![Clojars Project](http://clojars.org/metosin/malli/latest-version.svg)](http://clojars.org/metosin/malli) -Malli requires Clojure 1.11. +Malli requires Java 11 and Clojure 1.11. ## Quickstart diff --git a/deps.edn b/deps.edn index 47ac6fe00..ddf9b5580 100644 --- a/deps.edn +++ b/deps.edn @@ -8,7 +8,7 @@ mvxcvi/arrangement {:mvn/version "2.1.0"}} :aliases {:test {:extra-paths ["test"] :extra-deps {com.gfredericks/test.chuck {:mvn/version "0.2.14"} - lambdaisland/kaocha {:mvn/version "1.87.1366"} + lambdaisland/kaocha {:mvn/version "1.88.1376"} lambdaisland/kaocha-cljs {:mvn/version "1.5.154"} org.babashka/sci {:mvn/version "0.8.41"} lambdaisland/kaocha-junit-xml {:mvn/version "1.17.101"} @@ -19,7 +19,7 @@ prismatic/schema {:mvn/version "1.4.1"} minimallist/minimallist {:mvn/version "0.0.10"} net.cgrand/seqexp {:mvn/version "0.6.2"} - djblue/portal {:mvn/version "0.53.0"} + djblue/portal {:mvn/version "0.55.1"} meta-merge/meta-merge {:mvn/version "1.0.0"} expound/expound {:mvn/version "0.9.0"} lambdaisland/deep-diff {:mvn/version "0.0-47"} @@ -49,7 +49,7 @@ org.clojure/tools.namespace #_:clj-kondo/ignore {:mvn/version "RELEASE"}}} :shadow {:extra-paths ["app"] - :extra-deps {thheller/shadow-cljs {:mvn/version "2.28.2"} + :extra-deps {thheller/shadow-cljs {:mvn/version "2.28.3"} binaryage/devtools {:mvn/version "1.0.7"}}} :slow {:extra-deps {io.dominic/slow-namespace-clj {:git/url "https://git.sr.ht/~severeoverfl0w/slow-namespace-clj" diff --git a/pom.xml b/pom.xml index ab776fc64..a44127138 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 metosin malli - 0.15.0 + 0.16.0 malli @@ -15,7 +15,7 @@ https://github.com/metosin/malli scm:git:git://github.com/metosin/malli.git scm:git:ssh://git@github.com/metosin/malli.git - 0.15.0 + 0.16.0 diff --git a/src/malli/clj_kondo.cljc b/src/malli/clj_kondo.cljc index 4b3e90935..96971bd38 100644 --- a/src/malli/clj_kondo.cljc +++ b/src/malli/clj_kondo.cljc @@ -129,10 +129,10 @@ {:op :rest :spec child} :seqable)) -(defmethod accept :+ [_ _ children options] (-seqable-or-rest children options)) -(defmethod accept :* [_ _ children options] (-seqable-or-rest children options)) -(defmethod accept :? [_ _ children options] (-seqable-or-rest children options)) -(defmethod accept :repeat [_ _ children options] (-seqable-or-rest children options)) +(defmethod accept :+ [_ _ children options] (-seqable-or-rest children options)) +(defmethod accept :* [_ _ children options] (-seqable-or-rest children options)) +(defmethod accept :? [_ _ children options] (-seqable-or-rest children options)) +(defmethod accept :repeat [_ _ children options] (-seqable-or-rest children options)) (defmethod accept :cat [_ _ children _] children) (defmethod accept :catn [_ _ children _] (mapv last children)) diff --git a/src/malli/core.cljc b/src/malli/core.cljc index e353d7ec8..149b6f7ec 100644 --- a/src/malli/core.cljc +++ b/src/malli/core.cljc @@ -2366,7 +2366,8 @@ (defn -default-sci-options [] {:preset :termination-safe - :aliases {'str 'clojure.string} + :aliases {'str 'clojure.string + 'm 'malli.core} :namespaces {'malli.core {'properties properties 'type type 'children children diff --git a/src/malli/error.cljc b/src/malli/error.cljc index bc55cfe29..5310d7be6 100644 --- a/src/malli/error.cljc +++ b/src/malli/error.cljc @@ -3,9 +3,7 @@ [malli.core :as m] [malli.util :as mu])) -(defn- -pr-str [v] - #?(:clj (pr-str v) - :cljs (str v))) +(defn -pr-str [v] #?(:clj (pr-str v), :cljs (str v))) (defn -pred-min-max-error-fn [{:keys [pred message]}] (fn [{:keys [schema value]} _] diff --git a/src/malli/experimental/time.cljc b/src/malli/experimental/time.cljc index a9e9e6683..3b0b08609 100644 --- a/src/malli/experimental/time.cljc +++ b/src/malli/experimental/time.cljc @@ -33,12 +33,12 @@ "Periods are not comparable in the java Comparable sense, instead this performs simple units-by-units comparison. So a period of 1 year will always compare greater than a period of 13 months and similar for days and months." [^Period p1 ^Period p2] - (let [years1 #?(:clj (.getYears p1) :cljs (.years p1)) - years2 #?(:clj (.getYears p2) :cljs (.years p2)) + (let [years1 #?(:clj (.getYears p1) :cljs (.years p1)) + years2 #?(:clj (.getYears p2) :cljs (.years p2)) months1 #?(:clj (.getMonths p1) :cljs (.months p1)) months2 #?(:clj (.getMonths p2) :cljs (.months p2)) - days1 #?(:clj (.getDays p1) :cljs (.days p1)) - days2 #?(:clj (.getDays p2) :cljs (.days p2))] + days1 #?(:clj (.getDays p1) :cljs (.days p1)) + days2 #?(:clj (.getDays p2) :cljs (.days p2))] (cond (not (= years1 years2)) (- years1 years2) (not (= months1 months2)) (- months1 months2) @@ -52,8 +52,8 @@ (if (and (instance? Period min) (instance? Period max)) (fn [^Period x] (and - (not (pos? (compare-periods x max))) - (not (pos? (compare-periods min x))))) + (not (pos? (compare-periods x max))) + (not (pos? (compare-periods min x))))) (fn [x] (and (<= x max) (<= min x)))) min (fn [x] (if (instance? Period min) @@ -66,14 +66,14 @@ (defn -temporal-schema [{:keys [type class type-properties]}] (m/-simple-schema - (cond-> - {:type type - :pred (fn pred [x] - #?(:clj (.isInstance ^Class class x) - :cljs (instance? class x))) - :property-pred (-min-max-pred nil)} - type-properties - (assoc :type-properties type-properties)))) + (cond-> + {:type type + :pred (fn pred [x] + #?(:clj (.isInstance ^Class class x) + :cljs (instance? class x))) + :property-pred (-min-max-pred nil)} + type-properties + (assoc :type-properties type-properties)))) #?(:cljs (defn createTemporalQuery [f] diff --git a/src/malli/experimental/time/generator.cljc b/src/malli/experimental/time/generator.cljc index 046807251..7913cb259 100644 --- a/src/malli/experimental/time/generator.cljc +++ b/src/malli/experimental/time/generator.cljc @@ -135,22 +135,22 @@ floor-min (fn [v] (if (nil? v) min-int (max min-int v))) {^Period mn :min ^Period mx :max ^Period gen-min :gen/min ^Period gen-max :gen/max} (merge - (m/type-properties schema options) - (m/properties schema options)) + (m/type-properties schema options) + (m/properties schema options)) _ (when (and mn gen-min (not (pos? (time/compare-periods gen-min min)))) (m/-fail! ::mg/invalid-property {:key :gen/min, :value gen-min, :min min})) - _ (when (and mx gen-max (not (pos? (time/compare-periods max gen-max)))) + _ (when (and mx gen-max (not (pos? (time/compare-periods max gen-max)))) (m/-fail! ::mg/invalid-property {:key :gen/max, :value gen-min, :max min})) mn (or mn gen-min) mx (or mx gen-max) - min-years (when mn (zero->nil (.getYears mn))), max-years (when mx (zero->nil (.getYears mx))) + min-years (when mn (zero->nil (.getYears mn))), max-years (when mx (zero->nil (.getYears mx))) min-months (when mn (zero->nil (.getMonths mn))), max-months (when mx (zero->nil (.getMonths mx))) - min-days (when mn (zero->nil (.getDays mn))), max-days (when mx (zero->nil (.getDays mx)))] + min-days (when mn (zero->nil (.getDays mn))), max-days (when mx (zero->nil (.getDays mx)))] (->> - (gen/tuple - ;; Period constructor only accepts java type `int` not `long`, clamp the values - (gen/large-integer* {:min (floor-min min-years) :max (ceil-max max-years)}) - (gen/large-integer* {:min (floor-min min-months) :max (ceil-max max-months)}) - (gen/large-integer* {:min (floor-min min-days) :max (ceil-max max-days)})) - (gen/fmap (fn [[years months days]] - (. Period of years months days)))))) + (gen/tuple + ;; Period constructor only accepts java type `int` not `long`, clamp the values + (gen/large-integer* {:min (floor-min min-years) :max (ceil-max max-years)}) + (gen/large-integer* {:min (floor-min min-months) :max (ceil-max max-months)}) + (gen/large-integer* {:min (floor-min min-days) :max (ceil-max max-days)})) + (gen/fmap (fn [[years months days]] + (. Period of years months days)))))) diff --git a/src/malli/transform.cljc b/src/malli/transform.cljc index 2f183b254..b8dc79759 100644 --- a/src/malli/transform.cljc +++ b/src/malli/transform.cljc @@ -399,15 +399,15 @@ strip-map-of (fn [stage] {:compile (fn [schema options] (let [entry-schema (m/into-schema :tuple nil (m/children schema) options) - valid? (m/validator entry-schema options)] + valid? (m/validator entry-schema options)] {stage (fn [x] - (reduce (fn [acc entry] - (if (valid? entry) - (apply assoc acc entry) - acc)) (empty x) x))}))})] + (reduce (fn [acc entry] + (if (valid? entry) + (apply assoc acc entry) + acc)) (empty x) x))}))})] (transformer - {:decoders {:map strip-map, :map-of (strip-map-of :leave)} - :encoders {:map strip-map, :map-of (strip-map-of :enter)}})))) + {:decoders {:map strip-map, :map-of (strip-map-of :leave)} + :encoders {:map strip-map, :map-of (strip-map-of :enter)}})))) (defn key-transformer [{:keys [decode encode types] :or {types #{:map}}}] (let [transform (fn [f stage] (when f {stage (-transform-map-keys f)}))] diff --git a/test/malli/core_test.cljc b/test/malli/core_test.cljc index 52833aac7..a7a326443 100644 --- a/test/malli/core_test.cljc +++ b/test/malli/core_test.cljc @@ -2426,13 +2426,13 @@ (is (nil? (explain-times function-schema-validation-times schema2 (fn [x y] (unchecked-add x y))))) (testing "exception in execution causes single error to root schema path" - (is (results= {:schema [:=> [:cat int? int?] int?] - :value single-arity - :errors [{:path [] - :in [] - :schema [:=> [:cat int? int?] int?] - :value single-arity}]} - (m/explain schema2 single-arity)))) + (is (results= {:schema [:=> [:cat int? int?] int?] + :value single-arity + :errors [{:path [] + :in [] + :schema [:=> [:cat int? int?] int?] + :value single-arity}]} + (m/explain schema2 single-arity)))) (testing "error in output adds error to child in path 1" (let [f (fn [x y] (str x y))] @@ -2527,7 +2527,7 @@ (testing "guards" (let [guard (fn [[[x y] z]] (= (str x y) z)) schema (m/schema - [:=> [:cat :int :int] string? [:fn guard]] + [:=> [:cat :int :int] :string [:fn guard]] {::m/function-checker mg/function-checker}) valid (fn [x y] (str x y)) invalid (fn [x y] (str x "-" y))] @@ -2535,7 +2535,7 @@ (is (= {:type :=>, :input {:type :cat :children [{:type :int} {:type :int}]}, - :output {:type 'string?}, + :output {:type :string}, :guard {:type :fn :value guard}} (m/ast schema)))