Fork me on GitHub
#malli
<
2020-03-09
>
Vincent Cantin02:03:45

@ikitommi https://github.com/cgrand/seqexp will need some adjustments if we want to use it in Malli: • Its implementation is not cross platform. • The maps returned by se/exec contain the keyed groups in the middle of :rest and :match , that could be a problem when the keys of those groups are controlled by Malli’s users.

ikitommi06:03:02

@vincent.cantin ok. The cross-platform should be doable, ig Cristophe takes PRS (there should be an issue about that), not sure about the second. If that is not a good base lib to use, do you have plans on using something else? or from scratch?

Vincent Cantin06:03:05

I started to scratch my head about a new impl this morning. What's next depends on what features we want to offer the users.

ikitommi06:03:18

just commented on the issue

Vincent Cantin06:03:28

I think that an optimized & naive impl might be faster on most use cases compared to a general algorith that works in theory faster and cover all edge cases. I would like to put them to a benchmark on realworld usages.

ikitommi08:03:33

What kind of edge cases would not be covered using a naive impl? Benchmarks most welcome!

Vincent Cantin02:03:39

All the use cases would be covered by using a naive impl. Some edge cases might have a high computational cost in a naive impl while a smarter impl would mitigate the cost of their parsing. The edge cases I am thinking about are consecutive sequences of variable length. But I am not sure if it is a real concern or my imagination.

ikitommi06:03:20

did a quick draft of a swappable default registry: idea that the default registry could be bootstrapped into something that satisifes m/Registry protocol. There could be malli.mutable with an alternative impl using a extra atom to look for the schemas and malli.mutable/register!to register schemas into that. This would be a simple -> easy helper, already not happy with that. Comments welcome https://github.com/metosin/malli/pull/188

ikitommi14:03:51

;; JVM started with -Dmalli.core.registry=malli.mutable/registry

(require '[malli.core :as m])
(require '[malli.mutable :as mm])

(mm/register! ::age [:and int? [:> 18]])

(m/validate ::age 20)
; => true

Vincent Cantin02:03:35

I also don’t like the idea to lose the property of working with immutable values.

Vincent Cantin02:03:18

I would suggest users who don’t want to have to pass the registry as option to Malli all the time to just create their own wrapper functions.

;; in my-ns
(defn validate [schema data options]
  (m/validate schema data (assoc options :registry my-registry)))

Vincent Cantin02:03:43

I was facing the same situation in projects which use Vrac, and I used the wrapper pattern everywhere. It’s really not a big deal and it keep the satisfaction of working in an environment where we don’t even have to think about the side effects.

eskos07:03:35

Is cross-platform regex even possible? Beyond basics I don’t think JS/Java/C# regex engines are even close to compatible with each other.

Vincent Cantin09:03:46

we are talking about validating data structures, not string content.

eskos09:03:16

:thinking_face:

eskos10:03:00

Right, thank you. I got confused, quite obviously 🙂

shaunxcode18:03:34

are recursive schemas possible w/ malli?

shaunxcode18:03:25

e.g. defining a schema for a {:name "something" :kids [{:name "something" :kids [....]}]}

shaunxcode19:03:42

sorry just reading the whole of that linked issue and I see you guys are putting a lot of thought and effort into your approach so I will wait and see!

zilti20:03:37

I am about to start to try generating Malli schemas from PostgreSQL metadata. Very curious how far I can take this. If I find a way to store additional custom metadata in the database, I could end up generating 90% of a form simply by converting Postgres metadata, the rest being the layout.

👍 8
eskos08:03:48

Just curious, what kind of metadata you mean? PostgreSQL’s information schema is already quite extensive…

beders12:03:03

I have some code that does the same. I wasn't able to find a good solution for restricting string length. Maybe that has changed in the meantime.

eskos13:03:53

In PostgreSQL `TEXT` is string with infinite length (_=<https://wiki.postgresql.org/wiki/FAQ#What_is_the_maximum_size_for_a_row.2C_a_table.2C_and_a_database.3F|1GB> because that is any field’s maximum size_); string with specific maximum should be done with `VARCHAR` columns in which case `information_schema.columns` `character_maximum_length` has the column’s size limit information.

eskos13:03:31

Assuming I’ve understood correctly, I seem to have a lousy track record on that part this week… 🙂

viesti08:03:49

The JDBC API also offers metadata, but probable less than direct PostgreSQL use. Prior art in spec land: • https://github.com/tatut/specqlhttps://github.com/viesti/table-spec

viesti08:03:59

@U2APCNHCN the specql implementation might be really good help in looking what postgresql offers

viesti16:03:44

yup, although I have a feeling that it might lack info on postgresql specific extensions

zilti18:03:57

Yes, DatabaseMetaData is what I currently use. My showstopper right now is that I can't get the data transformations to work...

zilti18:03:26

I haven't heard of specql so far, but I will give it a look

eskos07:03:10

Might be just me but if I were doing something very product specific, I’d steer far away from any kind of abstraction and just go as raw and bare in as possible… 🙂

zilti10:03:48

Well I think the problem wih going as raw and bare as possible is that you lose all the flexibility. And we're going to need that flexibility. My competition for creating forms are airtable and typeform. And I'd prefer we don't use either of those for our product