Skip to content

Commit

Permalink
Deprecate wrap-hl-req-res-model
Browse files Browse the repository at this point in the history
  • Loading branch information
FieryCod committed Dec 5, 2021
1 parent 78b6462 commit e017d4f
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## 0.1.1
- Deprecate `wrap-hl-req-res-model`. Use `ring<->hl-middleware` instead.

## 0.1.0
- Add support for async non-async handlers
- Support all Ring types
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This is why holy-lambda-ring-adapter was released. An adapter is a part of holy-
- [HttpApi](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop.html#http-api-examples)
- Java Version >= 11
- GraalVM Native Image >= 21.2.0
- Holy Lambda >= 0.6.0 [all backends: [native](https://fierycod.github.io/holy-lambda/#/native-backend-tutorial), [babashka](https://fierycod.github.io/holy-lambda/#/babashka-backend-tutorial), [clojure](https://fierycod.github.io/holy-lambda/#/clojure-backend-tutorial)]
- Holy Lambda >= 0.6.0 [all backends: [native](https://fierycod.github.io/holy-lambda/#/native-backend-tutorial), [babashka](https://fierycod.github.io/holy-lambda/#/babashka-backend-tutorial), [clojure](https://fierycod.github.io/holy-lambda/#/clojure-backend-tutorial)

## Usage
- **With plain [ring](https://github.com/ring-clojure/ring)**
Expand All @@ -43,7 +43,7 @@ This is why holy-lambda-ring-adapter was released. An adapter is a part of holy-
:headers {}
:body \"Hello World\"}

(def HttpApiProxyGateway (hlra/wrap-hl-req-res-model ring-handler))
(def HttpApiProxyGateway (hlra/ring<->hl-middleware ring-handler))

(h/entrypoint [#'HttpApiProxyGateway])
```
Expand All @@ -63,7 +63,7 @@ This is why holy-lambda-ring-adapter was released. An adapter is a part of holy-
:coercion coerction
:middleware middlewares}})))

(def HttpApiProxyGateway (hlra/wrap-hl-req-res-model muuntaja-ring-handler))
(def HttpApiProxyGateway (hlra/ring<->hl-middleware muuntaja-ring-handler))

(h/entrypoint [#'HttpApiProxyGateway])
```
Expand Down
2 changes: 1 addition & 1 deletion examples/babashka/deps.edn
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{:paths ["src"]
:deps {io.github.FieryCod/holy-lambda {:mvn/version "0.6.1"}
:deps {io.github.FieryCod/holy-lambda {:mvn/version "0.6.3"}
io.github.FieryCod/holy-lambda-ring-adapter {:local/root "../../"}}}
2 changes: 1 addition & 1 deletion examples/babashka/src/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
[fierycod.holy-lambda-ring-adapter.core :as hlra]
[fierycod.holy-lambda.core :as h]))

(def HttpApiGatewayProxy (hlra/wrap-hl-req-res-model handler/router))
(def HttpApiGatewayProxy (hlra/ring<->hl-middleware handler/router))

(h/entrypoint [#'HttpApiGatewayProxy])
2 changes: 1 addition & 1 deletion examples/native/bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:deps/root "./modules/holy-lambda-babashka-tasks"
:sha "e6c47274a2bfc7576a9da0ccdbc079c1e83bee17"}
io.github.FieryCod/holy-lambda-ring-adapter {:local/root "../../"}
io.github.FieryCod/holy-lambda {:mvn/version "0.6.2"}}
io.github.FieryCod/holy-lambda {:mvn/version "0.6.3"}}

;; Minimal babashka version which should be used in conjuction with holy-lambda
:min-bb-version "0.3.7"
Expand Down
2 changes: 1 addition & 1 deletion examples/native/src/example/lambda.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
[fierycod.holy-lambda-ring-adapter.core :as hra]))

(def handler (:ring-handler (component/start (routes/->ring-handler-component {}))))
(def HttpAPIProxyGateway (hra/wrap-hl-req-res-model handler))
(def HttpAPIProxyGateway (hra/ring<->hl-middleware handler))

(h/entrypoint [#'HttpAPIProxyGateway])
9 changes: 7 additions & 2 deletions src/fierycod/holy_lambda_ring_adapter/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
(h/entrypoint [#'HttpApiProxyGateway])
```"
[response]
(let [^RingResponseBody body (:body response)
{:keys [body encoded?]} (impl/to-hl-response-body body)]
(let [^impl/RingResponseBody body (:body response)
{:keys [body encoded?]} (impl/to-hl-response-body body)]
{:statusCode (:status response)
:body body
:isBase64Encoded encoded?
Expand Down Expand Up @@ -140,3 +140,8 @@
(handler (hl-request->ring-request!! request)
(fn [response] (respond (ring-response->hl-response response)))
raise))))

(def ^:deprecated wrap-hl-req-res-model
"DEPRECATED. Subject to remove in 0.5.0.
Use `ring<->hl-middleware` instead!"
ring<->hl-middleware)
2 changes: 0 additions & 2 deletions src/fierycod/holy_lambda_ring_adapter/impl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
[clojure.lang IPersistentCollection])
#?(:bb
(:require
[clojure.string :as s]
[clojure.java.io :as io])
:clj
(:require
[ring.util.response :as resp]
[clojure.string :as s]
[clojure.java.io :as io])))

#?(:bb nil
Expand Down
18 changes: 9 additions & 9 deletions test/fierycod/holy_lambda_ring_adapter/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@
:body "hello world HTTP/1.1",
:isBase64Encoded false,
:headers {"something" "something"}}
((hra/wrap-hl-req-res-model basic-ring-handler) request2)))
((hra/ring<->hl-middleware basic-ring-handler) request2)))
(t/is (= {:statusCode 200,
:body "hello world HTTP/1.1",
:isBase64Encoded false,
:headers {"something" "something"}}
((hra/wrap-hl-req-res-model basic-ring-handler-async) request2 identity identity))))))
((hra/ring<->hl-middleware basic-ring-handler-async) request2 identity identity))))))

(t/deftest http-api-json-coerce-1
(t/testing "json coercion should work"
Expand Down Expand Up @@ -247,14 +247,14 @@
:body "eyJoZWxsbyI6IndvcmxkIiwiaW5uZXItYm9keSI6eyJoZWxsbyI6IndvcmxkIn19",
:isBase64Encoded true,
:headers {"Content-Type" "application/json; charset=utf-8"}}
((hra/wrap-hl-req-res-model handler) request)))
((hra/ring<->hl-middleware handler) request)))

;; The case where (HL >= 0.6.2) does automatically decodes the input
(t/is (= {:statusCode 200,
:body "eyJoZWxsbyI6IndvcmxkIiwiaW5uZXItYm9keSI6eyJoZWxsbyI6IndvcmxkIn19",
:isBase64Encoded true,
:headers {"Content-Type" "application/json; charset=utf-8"}}
((hra/wrap-hl-req-res-model handler) (-> request
((hra/ring<->hl-middleware handler) (-> request
(assoc-in [:event :body] "{\n\t\"hello\": \"world\"\n}")
(assoc-in [:event :body-parsed] {:hello "world"}))))))))

Expand Down Expand Up @@ -304,17 +304,17 @@
:body "eyJoZWxsbyI6IndvcmxkIiwiZm9ybS1wYXJhbXMiOnsiaGVsbG8iOiJ3b3JsZCJ9fQ==",
:isBase64Encoded true,
:headers {"Content-Type" "application/json; charset=utf-8"}}
((hra/wrap-hl-req-res-model handler) request)))
((hra/ring<->hl-middleware handler) request)))
(t/is (= {:statusCode 200,
:body "eyJoZWxsbyI6IndvcmxkIiwiZm9ybS1wYXJhbXMiOnsiYTMiOiIzIiwiYTkiOiI5IiwiYTciOiI3IiwiYTYiOiI2IiwiYTgiOiI4IiwiYSI6WyIxIiwiMiIsIjMiXSwiYTQiOiI0IiwiYTEiOiIxIiwiYTUiOiI1IiwiYTIiOiIyIn19",
:isBase64Encoded true,
:headers {"Content-Type" "application/json; charset=utf-8"}}
((hra/wrap-hl-req-res-model handler) (assoc-in request [:event :body] "a3=3&a9=9&a7=7&a6=6&a8=8&a4=4&a1=1&a5=5&a2=2&a=1&a=2&a=3"))))
((hra/ring<->hl-middleware handler) (assoc-in request [:event :body] "a3=3&a9=9&a7=7&a6=6&a8=8&a4=4&a1=1&a5=5&a2=2&a=1&a=2&a=3"))))
(t/is (= {:statusCode 200,
:body "eyJoZWxsbyI6IndvcmxkIiwiZm9ybS1wYXJhbXMiOnsiYTMiOiIzIiwiYTkiOiI5IiwiYTciOiI3IiwiYTYiOiI2IiwiYTgiOiI4IiwiYSI6WyIxIiwiMiIsIjMiXSwiYTQiOiI0IiwiYTEiOiIxIiwiYTUiOiI1IiwiSGVsbG8gV29ybGQgSXQncyBNZSBZb3UgTG9va2luZyBGb3IiOiJIZWxsbyBXb3JsZCAhICEgISIsImEyIjoiMiJ9fQ==",
:isBase64Encoded true,
:headers {"Content-Type" "application/json; charset=utf-8"}}
((hra/wrap-hl-req-res-model handler) (assoc-in request [:event :body] "a3=3&a9=9&a7=7&a6=6&a8=8&a4=4&a1=1&a5=5&Hello+World+It%27s+Me+You+Looking+For=Hello+World+%21+%21+%21&a2=2&a=1&a=2&a=3")))))))
((hra/ring<->hl-middleware handler) (assoc-in request [:event :body] "a3=3&a9=9&a7=7&a6=6&a8=8&a4=4&a1=1&a5=5&Hello+World+It%27s+Me+You+Looking+For=Hello+World+%21+%21+%21&a2=2&a=1&a=2&a=3")))))))

(t/deftest binary-alike-data-response-1
(t/testing "should correctly base64 encode a file"
Expand All @@ -336,7 +336,7 @@
:ctx
{}}
file (io/file "test/fierycod/holy_lambda_ring_adapter/logo.png")
handler (hra/wrap-hl-req-res-model
handler (hra/ring<->hl-middleware
(->reitit-ring-handler
[["/" {:get {:handler (fn [_request]
(response/response file))}}]]))]
Expand All @@ -363,7 +363,7 @@
:ctx
{}}
resource (io/resource "logo.png")
handler (hra/wrap-hl-req-res-model
handler (hra/ring<->hl-middleware
(->reitit-ring-handler
[["/" {:get {:handler (fn [_request]
(response/response resource))}}]]))]
Expand Down

0 comments on commit e017d4f

Please sign in to comment.