reitit

Nik 2024-10-14T23:08:23.709989Z

Hi, I need some guidance on handling type coercion for nested entities. (this is bit long so will provide context below). I'm building an expense tracking app using biff framework (reitit for routing, malli for db schema, xtdb for db) Schema -

:transaction [:map
                 [:xt/id                     :uuid]
...
                 [:tx/memo                   :string]
                 [:tx/postings [:vector {:min 2}
                                [:map
                                 [:tx/account                    :string]
...
                                 [:tx/quantity {:optional true}  :double]]]]
                 ]
Recently I got to know about parameter type coercion which save up bits of code needed for common type casting operations. Setup steps in biff - https://clojurians.slack.com/archives/C013Y4VG20J/p1728770815530479?thread_ts=1728742333.237249&cid=C013Y4VG20J Biff uses middleware - reititi.middleware.params and muntaaja Goal - reitit should check and type cast nested entities. eg :tx/postings should be parsed as map and :tx/quantity should be a double. Expected parameters in request handlers => in parameters (form or query) -
{:posting [{:quantity 20.00, :account "Food"}, {:account "Checking"}]
Why nesting - posting on it own doesn't make much sense, it needs to under a transaction and there will be 2+ postings for any transaction. On HTML side, one convention is to use name of inputs to posting[0][quantity] to indicate a seq of maps to server. How wrap-nested-params in reitit handles them now -> https://clojurians.slack.com/archives/C013Y4VG20J/p1728778973225059?thread_ts=1728742333.237249&cid=C013Y4VG20J To tackle this where should I start making changes, some new middleware, something related to muntaja or the writing new coercer for malli-reititi I've read through the malli reitit coercion code but I'm afraid I only got half of what is happening (I think for my use case the string transformer is being used) Since the issue is specific to route parameters, I can create a simple setup without all other biff modules to test the changes

❤️ 1