Fork me on GitHub
#biff
<
2024-05-23
>
jf16:05:26

I've got some questions arising from trying to understand how biff/submit-tx works (apologies if my way of referring to things is a bit rough (/ non-standard?)): 1. https://github.com/jacobobryant/biff/blob/master/src/com/biffweb.clj#L702-L710: what is the point of the destructuring of ctx? The function body is simply (bxt/submit-tx ctx biff-tx). Is anything done with the destructured retry and node? I see the same thing with https://github.com/jacobobryant/biff/blob/master/src/com/biffweb.clj#L673-L690 as well. 2. is com.biffweb/biff-tx->xt at https://github.com/jacobobryant/biff/blob/master/src/com/biffweb.clj#L673 used? I see that com.biffweb/submit-tx calls com.biffweb.impl.xtdb/submit-tx, which then calls its own separate biff-tx->xt function I'm providing the code inline here for easy viewing:

;; com.biffweb

(defn biff-tx->xt ;; L673-690
  "Converts the given Biff transaction into an XT transaction.

  The elements of biff-tx may be maps (in which case they are treated as Biff
  operations) or vectors (in which case they are treated as XT operations). For
  example:

  [{:db/doc-type :user
    :xt/id #uuid \"...\"
    :user/name \"example\"}
   [:xtdb.api/put {:xt/id #uuid \"...\"}]]

  biff-tx may optionally be a function which takes ctx and returns a Biff
  transaction.

  See ."
  [{:keys [biff/now biff/db biff/malli-opts] :as ctx} biff-tx]
  (bxt/biff-tx->xt ctx biff-tx))

;; ...

(defn submit-tx ;; L702-710
  "High-level wrapper over xtdb.api/submit-tx. See biff-tx->xt.

  If retry is true, the transaction will be passed to submit-with-retries."
  [{:keys [biff.xtdb/retry biff.xtdb/node]
    :or {retry true}
    :as ctx}
   biff-tx]
  (bxt/submit-tx ctx biff-tx))

Jacob O'Bryant17:05:25

1. It's for documentation--e.g. if you look at the docstring in your editor, it'll presumably show the function arguments like so:

; com.biffweb/submit-tx
; ([{:keys [biff.xtdb/retry biff.xtdb/node], :or {retry true}, :as ctx} biff-tx])
;   High-level wrapper over xtdb.api/submit-tx. See biff-tx->xt.
; 
;   If retry is true, the transaction will be passed to submit-with-retries.
(that's how it looks with my editor setup anyway). Same goes for the auto-generated API docs on the website: https://biffweb.com/docs/api/xtdb/#submit-tx 2. It's not used anywhere else in com.biffweb or in the starter app, but it's there in case anyone wants to use it. com.biffweb is the public API for the Biff library code; anything in the com.biffweb.impl.* namespaces isn't meant to be used by library consumers/application developers (no guarantee there won't be breaking changes). Mainly that function is probably useful for people to experiment with in the repl, so you can take a Biff transaction and see the regular XTDB transaction that it gets turned into.

jf23:05:17

1. I think i get it now, but just to confirm this: so you mean to say it’s to document that those keys are used somewhere along the way, even if it’s not directly by com.biffweb/submit-tx ? 2. I see. I will experiment with calling com.biffweb/biff-tx->xt myself then. Thank you!

Jacob O'Bryant19:05:31

1. yep, that's correct!

👌 1
🙏 1