Compare commits
6 commits
master
...
judepayne-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdb0409889 | ||
|
|
8f921b4d1a | ||
|
|
8fc86b15a0 | ||
|
|
d76f26f5f1 | ||
|
|
7ed071f13b | ||
|
|
0acd7a1788 |
6 changed files with 20 additions and 32 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -6,4 +6,3 @@
|
||||||
.cache
|
.cache
|
||||||
.clj-kondo/babashka
|
.clj-kondo/babashka
|
||||||
.clj-kondo/rewrite-clj
|
.clj-kondo/rewrite-clj
|
||||||
src/scratch.clj
|
|
||||||
|
|
|
||||||
10
README.md
10
README.md
|
|
@ -77,7 +77,7 @@ On the JVM:
|
||||||
When calling `load-pod` with a string or vector of strings (or declaring it in your `bb.edn`),
|
When calling `load-pod` with a string or vector of strings (or declaring it in your `bb.edn`),
|
||||||
the pod is looked up on the local file system (either using the PATH, or using an absolute path).
|
the pod is looked up on the local file system (either using the PATH, or using an absolute path).
|
||||||
When it is called with a qualified symbol and a version - like `(load-pod 'org.babashka/aws "0.0.5")`
|
When it is called with a qualified symbol and a version - like `(load-pod 'org.babashka/aws "0.0.5")`
|
||||||
then it will be looked up in and downloaded from the [pod-registry](https://github.com/babashka/pod-registry). You can customize the file system location that `load-pod` will use by setting the `BABASHKA_PODS_DIR` environment variable.
|
then it will be looked up in and downloaded from the [pod-registry](https://github.com/babashka/pod-registry).
|
||||||
|
|
||||||
By default babashka will search for a pod binary matching your system's OS and arch. If you want to download
|
By default babashka will search for a pod binary matching your system's OS and arch. If you want to download
|
||||||
pods for a different OS / arch (e.g. for deployment to servers), you can set one or both of the following
|
pods for a different OS / arch (e.g. for deployment to servers), you can set one or both of the following
|
||||||
|
|
@ -130,7 +130,7 @@ light weight replacement for native interop (JNI, JNA, etc.).
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
Beyond the already available pods mentioned above, educational examples of pods
|
Beyond the already available pods mentioned above, eductional examples of pods
|
||||||
can be found [here](examples):
|
can be found [here](examples):
|
||||||
|
|
||||||
- [pod-lispyclouds-sqlite](examples/pod-lispyclouds-sqlite): a pod that
|
- [pod-lispyclouds-sqlite](examples/pod-lispyclouds-sqlite): a pod that
|
||||||
|
|
@ -228,7 +228,7 @@ JSON. It also declares that the pod exposes one namespace,
|
||||||
|
|
||||||
To encode payloads in EDN use `"edn"` and for Transit JSON use `"transit+json"`.
|
To encode payloads in EDN use `"edn"` and for Transit JSON use `"transit+json"`.
|
||||||
|
|
||||||
The pod encodes the above map to bencode and writes it to stdout. The pod client
|
The pod encodes the above map to bencode and writes it to stdoud. The pod client
|
||||||
reads this message from the pod's stdout.
|
reads this message from the pod's stdout.
|
||||||
|
|
||||||
Upon receiving this message, the pod client creates these namespaces and vars.
|
Upon receiving this message, the pod client creates these namespaces and vars.
|
||||||
|
|
@ -414,13 +414,13 @@ to the optional map passed to `transit/writer`. e.g.:
|
||||||
Currently sending metadata on arguments passed to a pod function is available only for the
|
Currently sending metadata on arguments passed to a pod function is available only for the
|
||||||
`transit+json` format and can be enabled on a per var basis.
|
`transit+json` format and can be enabled on a per var basis.
|
||||||
|
|
||||||
A pod can enable metadata to be read on arguments by sending the "arg-meta" field to "true"
|
A pod can enable metadata to be read on arguments by sending the "read-meta?" field to "true"
|
||||||
for the var representing that function. For example:
|
for the var representing that function. For example:
|
||||||
|
|
||||||
````clojure
|
````clojure
|
||||||
{:format :transit+json
|
{:format :transit+json
|
||||||
:namespaces [{:name "pod.babashka.demo"
|
:namespaces [{:name "pod.babashka.demo"
|
||||||
:vars [{"name" "round-trip" "arg-meta" "true"}]}]}
|
:vars [{"name" "round-trip" "read-meta?" "true"}]}]}
|
||||||
````
|
````
|
||||||
|
|
||||||
#### Deferred namespace loading
|
#### Deferred namespace loading
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
(String. bytes))
|
(String. bytes))
|
||||||
|
|
||||||
(defn bytes->boolean [^"[B" bytes]
|
(defn bytes->boolean [^"[B" bytes]
|
||||||
(= "true" (String. bytes)))
|
(boolean bytes))
|
||||||
|
|
||||||
(defn get-string [m k]
|
(defn get-string [m k]
|
||||||
(-> (get m k)
|
(-> (get m k)
|
||||||
|
|
@ -90,12 +90,14 @@
|
||||||
(let [wh (transit/write-handler tag-fn val-fn)]
|
(let [wh (transit/write-handler tag-fn val-fn)]
|
||||||
(swap! transit-default-write-handlers assoc *pod-id* wh)))
|
(swap! transit-default-write-handlers assoc *pod-id* wh)))
|
||||||
|
|
||||||
|
(defonce vars-with-metadata (atom {}))
|
||||||
|
|
||||||
(defn transit-json-write
|
(defn transit-json-write
|
||||||
[pod-id ^String s metadata?]
|
[pod-id ^String s metadata?]
|
||||||
(with-open [baos (java.io.ByteArrayOutputStream. 4096)]
|
(with-open [baos (java.io.ByteArrayOutputStream. 4096)]
|
||||||
(let [w (transit/writer baos :json (cond-> {:handlers (get @transit-write-handler-maps pod-id)
|
(let [w (transit/writer baos :json (merge {:handlers (get @transit-write-handler-maps pod-id)
|
||||||
:default-handler (get @transit-default-write-handlers pod-id)}
|
:default-handler (get @transit-default-write-handlers pod-id)}
|
||||||
metadata? (assoc :transform transit/write-meta)))]
|
(when metadata? {:transform transit/write-meta})))]
|
||||||
(transit/write w s)
|
(transit/write w s)
|
||||||
(str baos))))
|
(str baos))))
|
||||||
|
|
||||||
|
|
@ -107,7 +109,9 @@
|
||||||
write-fn (case format
|
write-fn (case format
|
||||||
:edn pr-str
|
:edn pr-str
|
||||||
:json cheshire/generate-string
|
:json cheshire/generate-string
|
||||||
:transit+json #(transit-json-write (:pod-id pod) % (:arg-meta opts)))
|
:transit+json #(transit-json-write
|
||||||
|
(:pod-id pod) %
|
||||||
|
(contains? (get @vars-with-metadata (:pod-id pod)) pod-var)))
|
||||||
id (next-id)
|
id (next-id)
|
||||||
chan (if handlers handlers
|
chan (if handlers handlers
|
||||||
(promise))
|
(promise))
|
||||||
|
|
@ -138,11 +142,13 @@
|
||||||
name-sym (if vmeta
|
name-sym (if vmeta
|
||||||
(with-meta name-sym vmeta)
|
(with-meta name-sym vmeta)
|
||||||
name-sym)
|
name-sym)
|
||||||
metadata? (get-maybe-boolean var "arg-meta")]
|
metadata? (get-maybe-boolean var "read-meta?")]
|
||||||
|
(when metadata?
|
||||||
|
(swap! vars-with-metadata update (:pod-id pod) #(conj (set %) sym)))
|
||||||
[name-sym
|
[name-sym
|
||||||
(or code
|
(or code
|
||||||
(fn [& args]
|
(fn [& args]
|
||||||
(let [res (invoke pod sym args {:async async? :arg-meta metadata?})]
|
(let [res (invoke pod sym args {:async async?})]
|
||||||
res)))]))
|
res)))]))
|
||||||
vars))
|
vars))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,9 +137,7 @@
|
||||||
"code" "(defn read-other-tag [x] [x x])"
|
"code" "(defn read-other-tag [x] [x x])"
|
||||||
"meta" "{:doc \"unread\"}"}
|
"meta" "{:doc \"unread\"}"}
|
||||||
{"name" "round-trip-meta"
|
{"name" "round-trip-meta"
|
||||||
"arg-meta" "true"}
|
"read-meta?" "true"}
|
||||||
{"name" "dont-round-trip-meta"
|
|
||||||
"arg-meta" "false"}
|
|
||||||
{"name" "-local-date-time"}
|
{"name" "-local-date-time"}
|
||||||
{"name" "transit-stuff"
|
{"name" "transit-stuff"
|
||||||
"code" "
|
"code" "
|
||||||
|
|
@ -246,14 +244,6 @@
|
||||||
"id" id
|
"id" id
|
||||||
"value" "#my/other-tag[1]"})
|
"value" "#my/other-tag[1]"})
|
||||||
pod.test-pod/round-trip-meta
|
pod.test-pod/round-trip-meta
|
||||||
(write out
|
|
||||||
{"status" ["done"]
|
|
||||||
"id" id
|
|
||||||
"value"
|
|
||||||
(case format
|
|
||||||
:transit+json (transit-json-write-meta (first args))
|
|
||||||
(write-fn (first args)))})
|
|
||||||
pod.test-pod/dont-round-trip-meta
|
|
||||||
(write out
|
(write out
|
||||||
{"status" ["done"]
|
{"status" ["done"]
|
||||||
"id" id
|
"id" id
|
||||||
|
|
|
||||||
|
|
@ -94,11 +94,6 @@
|
||||||
(= {:my-meta 3} (meta (first (pod.test-pod/round-trip-meta [(with-meta [3] {:my-meta 3})]))))
|
(= {:my-meta 3} (meta (first (pod.test-pod/round-trip-meta [(with-meta [3] {:my-meta 3})]))))
|
||||||
true))
|
true))
|
||||||
|
|
||||||
(def dont-round-trip-meta
|
|
||||||
(if (= "transit+json" fmt)
|
|
||||||
(= nil (meta (pod.test-pod/dont-round-trip-meta (with-meta [2] {:my-meta 2}))))
|
|
||||||
true))
|
|
||||||
|
|
||||||
(require '[pod.test-pod.only-code :as only-code])
|
(require '[pod.test-pod.only-code :as only-code])
|
||||||
(def should-be-1 (only-code/foo))
|
(def should-be-1 (only-code/foo))
|
||||||
|
|
||||||
|
|
@ -133,7 +128,6 @@
|
||||||
assoc-string-array
|
assoc-string-array
|
||||||
round-trip-meta
|
round-trip-meta
|
||||||
round-trip-meta-nested
|
round-trip-meta-nested
|
||||||
dont-round-trip-meta
|
|
||||||
should-be-1
|
should-be-1
|
||||||
add-sync-meta
|
add-sync-meta
|
||||||
error-meta
|
error-meta
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@
|
||||||
true ;; roundtrip string array
|
true ;; roundtrip string array
|
||||||
true ;; roundtrip metadata
|
true ;; roundtrip metadata
|
||||||
true ;; roundtrip metadata nested
|
true ;; roundtrip metadata nested
|
||||||
true ;; dont roundtrip metadata (when arg-meta "false"/ absent)
|
|
||||||
1
|
1
|
||||||
"add the arguments"
|
"add the arguments"
|
||||||
nil
|
nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue