From a56ad5976f13412382e698d77442e9a03a968cc6 Mon Sep 17 00:00:00 2001 From: Paul deGrandis Date: Fri, 24 Mar 2017 10:27:29 -0400 Subject: [PATCH 1/2] Transact action should support common encoding formats- JSON, Transit, edn, and Form-POST --- src/com/cognitect/vase/actions.clj | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/com/cognitect/vase/actions.clj b/src/com/cognitect/vase/actions.clj index 228210d..10feb51 100644 --- a/src/com/cognitect/vase/actions.clj +++ b/src/com/cognitect/vase/actions.clj @@ -98,6 +98,16 @@ (let [{:keys [path-params params json-params edn-params]} request] (merge (if (empty? path-params) {} (decode-map path-params)) params json-params edn-params))) +(defn resolve-payload-parameter + [request] + ;; Using `or` instead of not-found to prevent unnecessary lookups/evaluation + (or (get-in request [:json-params :payload]) + (get-in request [:transit-params :payload]) + (get-in request [:edn-params :payload]) + ;; There's no technical reason not to support forms, + ;; except for the lack of symmetry wrt `:payload` + (:form-params request))) + (def eav (juxt :e :a :v)) (defn apply-tx @@ -397,7 +407,7 @@ (let [;args# (merged-parameters ~'request) args# (mapv #(select-keys % ~(vec properties)) - (get-in ~'request [:json-params :payload])) + (resolve-payload-parameter ~'request)) tx-data# (~(tx-processor db-op) args#) conn# (:conn ~'request) response-body# (apply-tx From 51640c09cd2ca7f75ff5d945484d6e9e40a38e09 Mon Sep 17 00:00:00 2001 From: Paul deGrandis Date: Fri, 24 Mar 2017 11:00:55 -0400 Subject: [PATCH 2/2] Include transit-params in other actions via merged-params --- src/com/cognitect/vase/actions.clj | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/com/cognitect/vase/actions.clj b/src/com/cognitect/vase/actions.clj index 10feb51..7da7aa5 100644 --- a/src/com/cognitect/vase/actions.clj +++ b/src/com/cognitect/vase/actions.clj @@ -95,8 +95,12 @@ (defn merged-parameters [request] {:post [(map? %)]} - (let [{:keys [path-params params json-params edn-params]} request] - (merge (if (empty? path-params) {} (decode-map path-params)) params json-params edn-params))) + (let [{:keys [path-params params json-params transit-params edn-params]} request] + (merge (if (empty? path-params) {} (decode-map path-params)) + params + json-params + transit-params + edn-params))) (defn resolve-payload-parameter [request]