diff --git a/README.md b/README.md index 4ecb804..30f6f14 100644 --- a/README.md +++ b/README.md @@ -376,11 +376,15 @@ nil #### Metadata +##### From pod to pod client + +1. Fixed Metadata on vars + Pods may attach metadata to functions and macros by sending data to the pod client in a `"meta"` field as part of a `"var"` section. The metadata must be an appropriate map, encoded as an EDN string. This is only applicable to vars in the pod and will be ignored if the var refers to Client-side code, since metadata can already be defined -in those code blocks. +in those code blocks (see 'Dynamic Metadata' below to enable the encoding of metadata). For example, a pod can define a function called `add`: @@ -392,6 +396,32 @@ For example, a pod can define a function called `add`: "meta" "{:doc \"arithmetic addition of 2 arguments\" :arglists ([a b])}"}]}]} ``` +2. Dynamic Metadata + +Pods may send metadata on values returned to the client if metadata encoding is enabled +for the particular transport used by the pod. + +For example, if your pod uses `transit+json` as its format, you can enable metadata +encoding by adding `:transform transit/write-meta` (or whatever transit is aliased to) +to the optional map passed to `transit\writer`. e.g.: + +````clojure +(transit/writer baos :json {:transform transit/write-meta}) +```` + +##### From pod client to pod + +Currently sending metadata on arguments passed to a function is available only for the +`transit+json` format and must be explicitly enabled on a per var basis. + +For example a pod can enable metadata to be read on arguments for the `round-trip` function: + +````clojure +{:format :transit+json + :namespaces [{:name "pod.babashka.demo" + :vars [{"name" "round-trip" "read-metadata?" "true"}]}]} +```` + #### Deferred namespace loading When your pod exposes multiple namespaces that can be used independently from diff --git a/src/babashka/pods/impl.clj b/src/babashka/pods/impl.clj index d6ec922..c0c5356 100644 --- a/src/babashka/pods/impl.clj +++ b/src/babashka/pods/impl.clj @@ -142,7 +142,7 @@ name-sym (if vmeta (with-meta name-sym vmeta) name-sym) - meta-args? (get-maybe-boolean var "metadata?")] + meta-args? (get-maybe-boolean var "read-metadata?")] (when meta-args? (swap! vars-with-metadata-on-args update (:pod-id pod) conj sym)) [name-sym