malli

https://github.com/metosin/malli :malli:
ikitommi 2020-07-23T08:22:43.188700Z

sci will be an optional dependency, why? • faster standalone usage for JVM (2.5sec -> 0.5sec to load `malli.core`) • smaller js-bundles: 120kb -> 7kb first cut: https://github.com/metosin/malli/pull/227

ikitommi 2020-07-23T08:43:17.190900Z

to make the sci-integration explicit, might be a good idea to make the whole default options customizable, instead of just the default registry. would allow one to pass sci as the default :evaluator , one could pass in default custom localizations for error messages etc. Wrote an issue here: https://github.com/metosin/malli/issues/228

ikitommi 2020-07-23T08:44:02.191700Z

comments welcome. it’s a rainy day, should have few hours later today to do that.

plexus 2020-07-23T08:56:00.192200Z

should a schema-schema's properties delegate to the referenced schema?

plexus 2020-07-23T08:56:20.192400Z

(schema/properties (malli.core/-deref (schema/schema :ars/address)))
  (schema/properties (schema/schema :ars/address))

plexus 2020-07-23T08:56:56.193200Z

the first returns a properties map, the second returns nil. would be nice if it actually returned the properties of the child schema

plexus 2020-07-23T08:58:01.193800Z

(I'm upgrading our project to the latest Malli. Nice addition of RefSchema and schema-schema!)

plexus 2020-07-23T09:17:34.195900Z

I guess the question is how transparent a RefSchema is expected to be. We had our implementation of a RefSchema before Malli added it, and in our case we tried to make it largely transparent, e.g. it implements MapSchema and LensSchema which delegate to the child schema. Was very convenient but maybe you prefer to be explicit and have (if (satisfies? RefSchema s) (-deref s) s) checks

ikitommi 2020-07-23T09:20:50.198800Z

Good question. :schema can now have it's own properties: [::m/schema {:title "foo"} :ars/address]

ikitommi 2020-07-23T09:22:47.199900Z

would help if there was distinction between properties and derived/accumulated properties

ikitommi 2020-07-23T09:24:55.202700Z

properties are used in transforming schemas, e.g. into map-format. If they are looked from child, the map-format would duplicate the properties into ::m/schema

ikitommi 2020-07-23T09:26:30.205400Z

a new Protocol / method would solve that, but not sure if that's the right fix

plexus 2020-07-23T09:45:26.206900Z

makes sense to keep them separate if they have different uses, maybe some more helpers would already go a long way, there's no deref yet for instance, only -deref. A version of deref/resolve that checks for RefSchema and otherwise returns the schema directly would also be nice.

plexus 2020-07-23T09:46:33.207800Z

what about if you do an update-in, but one of the schemas on the path is not a map schema but a reference to a map schema? should that work? (we do stuff like that and it's quite handy :))

ikitommi 2020-07-23T13:33:05.208800Z

Merged the SCI Optional PR. From Changelog:

* 23.7.2020
  * **BREAKING:**: `sci` is not a default dependency. Enabling sci-support:
    * **Clojure**: add a dependency to `borkdude/sci`
    * **ClojureScript**: also require `sci.core` (directly or via `:preloads`)

1👍
ikitommi 2020-07-23T13:33:43.209300Z

before and after (a small sample app)

borkdude 2020-07-23T13:35:15.210500Z

What is the total size of the app before and after, un-gzipped? What does optimized mean, Clojure advanced?

ikitommi 2020-07-23T13:45:28.211600Z

here’s the javascript:

➜  malli git:(master) ✗ ls -lh app2-sci
total 1536
-rw-r--r--  1 tommi  staff   8.8K Jul 23 16:43 app.js
-rw-r--r--  1 tommi  staff   177K Jul 23 16:43 cljs.js
-rw-r--r--  1 tommi  staff    16K Jul 23 16:43 malli.js
-rw-r--r--  1 tommi  staff   2.0K Jul 23 16:43 manifest.edn
-rw-r--r--  1 tommi  staff   556K Jul 23 16:43 sci.js

➜  malli git:(master) ✗ ls -lh app2
total 288
-rw-r--r--  1 tommi  staff    10K Jul 23 16:41 app.js
-rw-r--r--  1 tommi  staff   102K Jul 23 16:41 cljs.js
-rw-r--r--  1 tommi  staff    24K Jul 23 16:41 malli.js
-rw-r--r--  1 tommi  staff   987B Jul 23 16:41 manifest.edn

ikitommi 2020-07-23T13:46:07.212Z

manually zipped:

➜  malli git:(master) ✗ ls -lh app2-sci
total 344
-rw-r--r--  1 tommi  staff   2.3K Jul 23 16:43 app.js.gz
-rw-r--r--  1 tommi  staff    35K Jul 23 16:43 cljs.js.gz
-rw-r--r--  1 tommi  staff   4.7K Jul 23 16:43 malli.js.gz
-rw-r--r--  1 tommi  staff   624B Jul 23 16:43 manifest.edn.gz
-rw-r--r--  1 tommi  staff   119K Jul 23 16:43 sci.js.gz

➜  malli git:(master) ✗ ls -lh app2
total 80
-rw-r--r--  1 tommi  staff   3.0K Jul 23 16:41 app.js.gz
-rw-r--r--  1 tommi  staff    22K Jul 23 16:41 cljs.js.gz
-rw-r--r--  1 tommi  staff   6.5K Jul 23 16:41 malli.js.gz
-rw-r--r--  1 tommi  staff   370B Jul 23 16:41 manifest.edn.gz

ikitommi 2020-07-23T13:46:54.213Z

the app itself is silly, bare-bones malli with few schemas: https://github.com/metosin/malli/blob/master/app/malli/app2.cljc

borkdude 2020-07-23T13:47:35.214Z

ok

ikitommi 2020-07-23T13:47:35.214100Z

shadow config: https://github.com/metosin/malli/blob/master/shadow-cljs.edn

borkdude 2020-07-23T13:48:05.214700Z

modules are a bit confusing since one thing can get randomly moved from one module to another

borkdude 2020-07-23T13:48:32.215100Z

but overall, this is a win for people who don't want to use sci

ikitommi 2020-07-23T13:52:22.216500Z

so total sizes: • js: 757,8kb -> 136kb • gz: 161kb -> 31,5kb , so 1/5 the size.

ikitommi 2020-07-23T13:54:34.218500Z

yup (javascript) is 223kB unpacked, so we can say malli can be small too. or batteries-included.

ikitommi 2020-07-23T14:00:42.220100Z

anyone btw interested in writing a malli->typescript transformer? in a project with both, might be useful, most likely fun

ikitommi 2020-07-23T14:01:48.220500Z

with yup, you can say:

type Person = yup.InferType<typeof personSchema>;

ikitommi 2020-07-23T14:02:43.221100Z

I don’t think it would be much more work than the malli -> JSON Schema.

ikitommi 2020-07-23T14:02:56.221300Z

might be wrong 🙂