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
|
||||
.clj-kondo/babashka
|
||||
.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`),
|
||||
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")`
|
||||
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
|
||||
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
|
||||
|
||||
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):
|
||||
|
||||
- [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"`.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
`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:
|
||||
|
||||
````clojure
|
||||
{:format :transit+json
|
||||
:namespaces [{:name "pod.babashka.demo"
|
||||
:vars [{"name" "round-trip" "arg-meta" "true"}]}]}
|
||||
:vars [{"name" "round-trip" "read-meta?" "true"}]}]}
|
||||
````
|
||||
|
||||
#### Deferred namespace loading
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
(String. bytes))
|
||||
|
||||
(defn bytes->boolean [^"[B" bytes]
|
||||
(= "true" (String. bytes)))
|
||||
(boolean bytes))
|
||||
|
||||
(defn get-string [m k]
|
||||
(-> (get m k)
|
||||
|
|
@ -90,12 +90,14 @@
|
|||
(let [wh (transit/write-handler tag-fn val-fn)]
|
||||
(swap! transit-default-write-handlers assoc *pod-id* wh)))
|
||||
|
||||
(defonce vars-with-metadata (atom {}))
|
||||
|
||||
(defn transit-json-write
|
||||
[pod-id ^String s metadata?]
|
||||
(with-open [baos (java.io.ByteArrayOutputStream. 4096)]
|
||||
(let [w (transit/writer baos :json (cond-> {:handlers (get @transit-write-handler-maps pod-id)
|
||||
:default-handler (get @transit-default-write-handlers pod-id)}
|
||||
metadata? (assoc :transform transit/write-meta)))]
|
||||
(let [w (transit/writer baos :json (merge {:handlers (get @transit-write-handler-maps pod-id)
|
||||
:default-handler (get @transit-default-write-handlers pod-id)}
|
||||
(when metadata? {:transform transit/write-meta})))]
|
||||
(transit/write w s)
|
||||
(str baos))))
|
||||
|
||||
|
|
@ -106,8 +108,10 @@
|
|||
chans (:chans pod)
|
||||
write-fn (case format
|
||||
:edn pr-str
|
||||
:json cheshire/generate-string
|
||||
:transit+json #(transit-json-write (:pod-id pod) % (:arg-meta opts)))
|
||||
:json cheshire/generate-string
|
||||
:transit+json #(transit-json-write
|
||||
(:pod-id pod) %
|
||||
(contains? (get @vars-with-metadata (:pod-id pod)) pod-var)))
|
||||
id (next-id)
|
||||
chan (if handlers handlers
|
||||
(promise))
|
||||
|
|
@ -138,11 +142,13 @@
|
|||
name-sym (if vmeta
|
||||
(with-meta name-sym vmeta)
|
||||
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
|
||||
(or code
|
||||
(fn [& args]
|
||||
(let [res (invoke pod sym args {:async async? :arg-meta metadata?})]
|
||||
(let [res (invoke pod sym args {:async async?})]
|
||||
res)))]))
|
||||
vars))
|
||||
|
||||
|
|
|
|||
|
|
@ -137,9 +137,7 @@
|
|||
"code" "(defn read-other-tag [x] [x x])"
|
||||
"meta" "{:doc \"unread\"}"}
|
||||
{"name" "round-trip-meta"
|
||||
"arg-meta" "true"}
|
||||
{"name" "dont-round-trip-meta"
|
||||
"arg-meta" "false"}
|
||||
"read-meta?" "true"}
|
||||
{"name" "-local-date-time"}
|
||||
{"name" "transit-stuff"
|
||||
"code" "
|
||||
|
|
@ -246,14 +244,6 @@
|
|||
"id" id
|
||||
"value" "#my/other-tag[1]"})
|
||||
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
|
||||
{"status" ["done"]
|
||||
"id" id
|
||||
|
|
|
|||
|
|
@ -94,11 +94,6 @@
|
|||
(= {:my-meta 3} (meta (first (pod.test-pod/round-trip-meta [(with-meta [3] {:my-meta 3})]))))
|
||||
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])
|
||||
(def should-be-1 (only-code/foo))
|
||||
|
||||
|
|
@ -133,7 +128,6 @@
|
|||
assoc-string-array
|
||||
round-trip-meta
|
||||
round-trip-meta-nested
|
||||
dont-round-trip-meta
|
||||
should-be-1
|
||||
add-sync-meta
|
||||
error-meta
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@
|
|||
true ;; roundtrip string array
|
||||
true ;; roundtrip metadata
|
||||
true ;; roundtrip metadata nested
|
||||
true ;; dont roundtrip metadata (when arg-meta "false"/ absent)
|
||||
1
|
||||
"add the arguments"
|
||||
nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue