Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intern defnk #56

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,20 @@ A new project is created for a function defined as `my-bb-function`. It will con
In `bb` language:
[source, clojure]
----
(defn handler [{:keys [headers body context] :as event}]
(defn handler [{:keys [headers body context]} :as event]
...)
; or
(defnk handler [body headers context]
...)
----
`event` is a map containing `:headers`, `:body` and `:context` keys.

`:headers` contains headers, as such:
`headers` contains headers, as such:
[source, clojure]
----
{:content-type "application/json"}
----

`:body` is the payload body. When passing a JSON object payload and using `bb` language, the payload will be automatically parsed as a Clojure map with keyword keys. There are cases where it's preferable to have string keys in the payload body, and it's possible to support them by setting `keywords: false` in the Function in `stack.yml`:
`body` is the payload body. When passing a JSON object payload and using `bb` language, the payload will be automatically parsed as a Clojure map with keyword keys. There are cases where it's preferable to have string keys in the payload body, and it's possible to support them by setting `keywords: false` in the Function in `stack.yml`:
[source, yml]
----
my-function:
Expand Down
6 changes: 4 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

## Supported Versions

The latest version in the most recent commit of the `main` branch.
The most recent commit of the `main` branch.

## Reporting a vulnerability
Please send an email to [email protected]. We take all reports seriously and will investigate each issue reported to us.
Please send an email to [email protected].

We take all reports seriously and will investigate each issue reported to us.

## What to expect after reporting a vulnerability

Expand Down
2 changes: 1 addition & 1 deletion examples/bb-hiccup/handler.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns handler
(:require view))

(defn handler [{:keys [body]}]
(defnk handler [body]
ccfontes marked this conversation as resolved.
Show resolved Hide resolved
ccfontes marked this conversation as resolved.
Show resolved Hide resolved
(view/render-page "My Page" body))
2 changes: 1 addition & 1 deletion examples/bb-map-context/handler.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns handler)

(defn handler [{:keys [body headers context]}]
(defnk handler [body headers context]
ccfontes marked this conversation as resolved.
Show resolved Hide resolved
ccfontes marked this conversation as resolved.
Show resolved Hide resolved
[(keys body) (vals body) (:content-type headers) (:upstream-url context)])
2 changes: 1 addition & 1 deletion examples/bb-map/handler.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns handler)

(defn handler [{:keys [body]}]
(defnk handler [body]
[(keys body) (vals body)])
2 changes: 1 addition & 1 deletion examples/bb-routes/handler.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns handler)

(defn handler [{:keys [request-method uri]}]
(defnk handler [request-method uri]
ccfontes marked this conversation as resolved.
Show resolved Hide resolved
ccfontes marked this conversation as resolved.
Show resolved Hide resolved
(case [request-method uri]
[:get "/"] "root"
[:get "/foo"] "foo"))
2 changes: 2 additions & 0 deletions template/bb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ RUN addgroup --system app && adduser --system --ingroup app app
USER app
WORKDIR $HOME

RUN bb prepare -Sdeps 'prismatic/plumbing {:mvn/version "0.6.0"}'

COPY --chown=app:app index.clj bb.edn lib merge_config.clj ./

COPY --chown=app:app function/bb.edn* function/bb.edn
Expand Down
3 changes: 3 additions & 0 deletions template/bb/index.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
[ring.util.walk :as ring-walk]
[secrets :refer [->secrets]]
[compojure.response :as response]
[plumbing.core :refer [defnk]]
[handler :as function]))

(intern 'clojure.core 'defnk #'defnk)

(def keywords? #(if (nil? %) true %))

(def fn-arg-cnt #(some-> % meta :arglists first count))
Expand Down
Loading