Skip to content

Commit

Permalink
Merge branch 'master' into reliable-and-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Nov 24, 2024
2 parents ec329c1 + 711ca00 commit c18ce8c
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/clojure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
matrix:
# Supported Java versions: LTS releases and latest
jdk: [8, 11, 17, 21]
clojure: [11]
clojure: [11, 12]

name: Java ${{ matrix.jdk }}

Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
with:
cli: latest
- name: Setup Node.js
uses: actions/setup-node@v4.0.3
uses: actions/setup-node@v4.1.0
with:
node-version: 16
cache: 'npm'
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ We use [Break Versioning][breakver]. The version numbers follow a `<major>.<mino

Malli is in well matured [alpha](README.md#alpha).

## 0.17.0 (UNRELEASED)

* **BREAKING**: `:gen/fmap` property requires its schema to create a generator.
* previous behavior defaulted to a `nil`-returning generator, even if the schema doesn't accept `nil`
* use `:gen/return nil` property to restore this behavior
* FIX: `malli.registry/{mode,type}` not respected in Babashka [#1124](https://github.com/metosin/malli/issues/1124)
* Updated dependencies:

```
fipp/fipp '0.6.26' to '0.6.27'
```

## 0.16.4 (2024-08-30)

* Distribute `:merge` over `:multi` [#1086](https://github.com/metosin/malli/pull/1086), see [documentation](README.md#distributive-schemas)
Expand Down
2 changes: 1 addition & 1 deletion bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@

test-bb {:doc "Run Babashka tests"
:extra-deps {org.babashka/spec.alpha {:git/url "https://github.com/babashka/spec.alpha"
:git/sha "951b49b8c173244e66443b8188e3ff928a0a71e7"}}
:git/sha "b6eb0f2208ab036c0a5d0e7235cb0b09d2feabb7"}}
:extra-paths ["src" "test"]
:task bb-test-runner/run-tests}}}
31 changes: 14 additions & 17 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
{:paths ["src" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.11.4"}
:deps {org.clojure/clojure {:mvn/version "1.12.0"}
borkdude/dynaload {:mvn/version "0.3.5"}
borkdude/edamame {:mvn/version "1.4.27"}
org.clojure/test.check {:mvn/version "1.1.1"}
;; pretty errors, optional deps
fipp/fipp {:mvn/version "0.6.26"}
fipp/fipp {:mvn/version "0.6.27"}
mvxcvi/arrangement {:mvn/version "2.1.0"}
;; for constrained schema generators
org.clojure/math.combinatorics {:mvn/version "0.1.6"}}
:aliases {:test {:extra-paths ["test"
;;remove me
"dev"]
:aliases {:test {:extra-paths ["test"]
:extra-deps {com.gfredericks/test.chuck {:mvn/version "0.2.14"}
lambdaisland/kaocha {:mvn/version "1.91.1392"}
lambdaisland/kaocha-cljs {:mvn/version "1.5.154"}
org.babashka/sci {:mvn/version "0.8.43"}
org.babashka/sci {:mvn/version "0.9.44"}
lambdaisland/kaocha-junit-xml {:mvn/version "1.17.101"}
metosin/spec-tools {:mvn/version "0.10.7"}
spec-provider/spec-provider {:mvn/version "0.4.14"}
metosin/schema-tools {:mvn/version "0.13.1"}
metosin/jsonista {:mvn/version "0.3.10"}
metosin/jsonista {:mvn/version "0.3.12"}
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.57.3"}
djblue/portal {:mvn/version "0.58.3"}
meta-merge/meta-merge {:mvn/version "1.0.0"}
expound/expound {:mvn/version "0.9.0"}
lambdaisland/deep-diff {:mvn/version "0.0-47"}
com.bhauman/spell-spec {:mvn/version "0.1.2"}
org.clojure/spec-alpha2 {:git/url "https://github.com/clojure/spec-alpha2.git"
:sha "4cbfa677c4cd66339f18e1c122222c05c69e0d8e"}}}
:sci {:extra-deps {org.babashka/sci {:mvn/version "0.8.43"}}}
:cherry {:extra-deps {io.github.squint-cljs/cherry {:git/sha "a0d53a290ab29e4de75de1be24e19eeee8d0a50a"}}}
:sci {:extra-deps {org.babashka/sci {:mvn/version "0.9.44"}}}
:cherry {:extra-deps {io.github.squint-cljs/cherry {:git/sha "bccd994556efca378984c5ac7fd973bda164923b"}}}
:test-sci {:extra-paths ["test-sci"]
:main-opts ["-m" "cljs-test-runner.main" "-d" "test-sci" "-d" "test"]}
:test-cherry {:extra-paths ["test-cherry"]
Expand All @@ -41,7 +38,7 @@
com.widdindustries/cljs.java-time {:mvn/version "0.1.20"}}
:extra-paths ["test" "cljs-test-runner-out/gen"]
:main-opts ["-m" "cljs-test-runner.main" "-d" "test"]}
:build {:deps {io.github.clojure/tools.build {:git/tag "v0.10.5" :git/sha "2a21b7a"}}
:build {:deps {io.github.clojure/tools.build {:git/tag "v0.10.6" :git/sha "52cf7d6"}}
:ns-default build}
:jmh {:paths ["target/uber.jar" "classes"]
:deps {jmh-clojure/jmh-clojure {:mvn/version "0.4.1"}
Expand All @@ -53,7 +50,7 @@
org.clojure/tools.namespace #_:clj-kondo/ignore {:mvn/version "RELEASE"}}}

:shadow {:extra-paths ["app"]
:extra-deps {thheller/shadow-cljs {:mvn/version "2.28.14"}
:extra-deps {thheller/shadow-cljs {:mvn/version "2.28.20"}
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"
Expand All @@ -72,12 +69,12 @@
:main-opts ["-m" "deps-deploy.deps-deploy" "install"
"malli.jar"]}
:graalvm {:extra-paths ["graal-test/src"]
:extra-deps {org.clojure/clojure {:mvn/version "1.11.4"}
org.babashka/sci {:mvn/version "0.8.43"}}}
:extra-deps {org.clojure/clojure {:mvn/version "1.12.0"}
org.babashka/sci {:mvn/version "0.9.44"}}}
:perf {:extra-paths ["perf"]
:extra-deps {criterium/criterium {:mvn/version "0.4.6"}
org.clojure/clojure {:mvn/version "1.11.4"}
com.clojure-goes-fast/clj-async-profiler {:mvn/version "1.2.2"}}
org.clojure/clojure {:mvn/version "1.12.0"}
com.clojure-goes-fast/clj-async-profiler {:mvn/version "1.5.0"}}
:jvm-opts ["-server"
"-Xmx4096m"
"-Dclojure.compiler.direct-linking=true"]}}}
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion perf/malli/perf/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[clj-async-profiler.core :as prof]))

(defn serve! []
(with-out-str (prof/serve-files 8080))
(with-out-str (prof/serve-ui 8080))
nil)

(defn clear! []
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<version>1.11.4</version>
<version>1.12.0</version>
</dependency>
<dependency>
<groupId>fipp</groupId>
<artifactId>fipp</artifactId>
<version>0.6.26</version>
<version>0.6.27</version>
</dependency>
<dependency>
<groupId>mvxcvi</groupId>
Expand Down
6 changes: 4 additions & 2 deletions src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2724,8 +2724,10 @@
(merge (predicate-schemas) (class-schemas) (comparator-schemas) (type-schemas) (sequence-schemas) (base-schemas)))

(def default-registry
(let [strict (identical? mr/mode "strict")
custom (identical? mr/type "custom")
(let [strict #?(:cljs (identical? mr/mode "strict")
:default (= mr/mode "strict"))
custom #?(:cljs (identical? mr/type "custom")
:default (= mr/type "custom"))
registry (if custom (mr/fast-registry {}) (mr/composite-registry (mr/fast-registry (default-schemas)) (mr/var-registry)))]
(when-not strict (mr/set-default-registry! registry))
(mr/registry (if strict registry (mr/custom-default-registry)))))
Expand Down
3 changes: 1 addition & 2 deletions src/malli/generator.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,7 @@
(-create-from-schema props options)
(-create-from-gen props schema options)
(m/-fail! ::no-generator {:options options
:schema schema
:form (m/form schema)}))]
:schema schema}))]
(or (-create-from-fmap gen props schema options)
gen)))

Expand Down
7 changes: 4 additions & 3 deletions src/malli/registry.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#?(:clj (:import (java.util HashMap Map))))

#?(:cljs (goog-define mode "default")
:clj (def mode (as-> (or (System/getProperty "malli.registry/mode") "default") $ (.intern $))))
:clj (def mode (or (System/getProperty "malli.registry/mode") "default")))

#?(:cljs (goog-define type "default")
:clj (def type (as-> (or (System/getProperty "malli.registry/type") "default") $ (.intern $))))
:clj (def type (or (System/getProperty "malli.registry/type") "default")))

(defprotocol Registry
(-schema [this type] "returns the schema from a registry")
Expand Down Expand Up @@ -40,7 +40,8 @@
(def ^:private registry* (atom (simple-registry {})))

(defn set-default-registry! [?registry]
(if-not (identical? mode "strict")
(if-not #?(:cljs (identical? mode "strict")
:default (= mode "strict"))
(reset! registry* (registry ?registry))
(throw (ex-info "can't set default registry, invalid mode" {:mode mode, :type type}))))

Expand Down
16 changes: 13 additions & 3 deletions test/malli/generator_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,14 @@

(testing "generator override"
(testing "without generator"
(let [schema [:fn {:gen/fmap '(fn [_] (rand-int 10))}
(let [schema [:fn {:gen/elements [5]
:gen/fmap '(fn [i] (rand-int i))}
'(fn [x] (<= 0 x 10))]
generator (mg/generator schema)]
(dotimes [_ 100]
(m/validate schema (mg/generate generator)))))
(let [v (mg/generate generator)]
(is (m/validate schema v))
(is (<= 0 v 5))))))
(testing "with generator"
(is (re-matches #"kikka_\d+" (mg/generate [:and {:gen/fmap '(partial str "kikka_")} pos-int?])))))

Expand Down Expand Up @@ -999,11 +1002,18 @@

(defn alphanumeric-char? [c]
{:pre [(char? c)]}
(let [i (int c)]
(let [int (fn [c]
#?(:clj (int c)
:cljs (.charCodeAt c 0)))
i (int c)]
(or (<= (int \a) i (int \z))
(<= (int \A) i (int \Z))
(<= (int \0) i (int \9)))))

(deftest alphanumeric-char?-test
(is (alphanumeric-char? \a))
(is (not (alphanumeric-char? \-))))

(defn alphanumeric-string? [s]
{:pre [(string? s)]}
(every? alphanumeric-char? s))
Expand Down
69 changes: 67 additions & 2 deletions test/malli/util_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,24 @@
(is (true? (m/validate
(mu/update schema :b identity)
{:a 1
:c "a string"}))))))
:c "a string"}))))
(testing "Multi schema can update its individual dispatch schemas"
(is (mu/equals (-> (m/schema [:multi {:dispatch :type}
[:sized [:map
[:type keyword?]
[:size int?]]]
[:human [:map
[:type keyword?]
[:name string?]
[:address [:map [:country keyword?]]]]]])
(mu/update :sized mu/select-keys [:size])
(mu/update :human mu/select-keys [:name :address]))
[:multi {:dispatch :type}
[:sized [:map
[:size int?]]]
[:human [:map
[:name string?]
[:address [:map [:country keyword?]]]]]])))))

(deftest assoc-in-test
(is (mu/equals (mu/assoc-in (m/schema [:vector int?]) [0] string?) [:vector string?]))
Expand All @@ -523,7 +540,55 @@
(is (mu/equals (mu/assoc-in (m/schema [:map]) [:a :b :c :d] int?)
[:map [:a [:map [:b [:map [:c [:map [:d int?]]]]]]]]))
(is (mu/equals (mu/assoc-in (m/schema [:ref {:registry {::a int?, ::b string?}} ::a]) [0] ::b) [:ref {:registry {::a int?, ::b string?}} ::b]))
(is (mu/equals (mu/assoc-in (m/schema [:schema int?]) [0] string?) [:schema string?])))
(is (mu/equals (mu/assoc-in (m/schema [:schema int?]) [0] string?) [:schema string?]))

(testing "Multi schema can use assoc-in to introduce new dispatch schemas"
(is (mu/equals (-> (m/schema [:multi {:dispatch :type}
[:sized [:map
[:type keyword?]
[:size int?]]]
[:human [:map
[:type keyword?]
[:name string?]
[:address [:map [:country keyword?]]]]]])
(mu/assoc-in [:robot] [:map
[:type keyword?]
[:serial-number string?]
[:charging-station [:map [:id string?]]]]))
[:multi {:dispatch :type}
[:sized [:map
[:type keyword?]
[:size int?]]]
[:human [:map
[:type keyword?]
[:name string?]
[:address [:map [:country keyword?]]]]]
[:robot [:map
[:type keyword?]
[:serial-number string?]
[:charging-station [:map [:id string?]]]]]])))
(testing "Multi schema can use assoc-in to extend existing schemas"
(is (mu/equals (-> (m/schema [:multi {:dispatch :type}
[:sized [:map
[:type keyword?]
[:size int?]]]
[:human [:map
[:type keyword?]
[:name string?]
[:address [:map [:country keyword?]]]]]])
(mu/assoc-in [:sized :unit] string?)
(mu/assoc-in [:human :address :state] string?))
[:multi {:dispatch :type}
[:sized [:map
[:type keyword?]
[:size int?]
[:unit string?]]]
[:human [:map
[:type keyword?]
[:name string?]
[:address [:map
[:country keyword?]
[:state string?]]]]]]))))

(deftest update-in-test
(is (mu/equals (mu/update-in (m/schema [:vector int?]) [0] (constantly string?)) [:vector string?]))
Expand Down

0 comments on commit c18ce8c

Please sign in to comment.