This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-19
Channels
- # babashka (13)
- # beginners (4)
- # biff (1)
- # cider (15)
- # clerk (1)
- # clojure (18)
- # clojure-europe (10)
- # clojure-nl (1)
- # clojure-uk (1)
- # core-logic (2)
- # core-typed (2)
- # datomic (23)
- # defnpodcast (1)
- # emacs (4)
- # fulcro (25)
- # hyperfiddle (8)
- # music (1)
- # off-topic (21)
- # podcasts-discuss (1)
- # polylith (6)
- # releases (1)
- # squint (19)
- # tools-deps (10)
Hello! Any tips for using fulcro-rad-datomic
with Entity Specs? F.ex. I would like to ensure that it is impossible to delete a Product if any Order refers to it… 🙏
I guess a custom :datomic/transact
in the Pathom env, which inspects the passed-in :tx-data and injects :db/ensure where appropriate would be the way to go...
Would wrapping the default datomic save middleware help somehow? Or do you mean copy & modify that one?
save middleware is just that: middleware. It is meant for you to add on layers to do whatever you need.
One of my production middlewares, for example, does:
(def middleware
(->
(after-effects/wrap-synchronous-after-effects) ; ONLY failure-tolerant synchronous effects, like cache refresh
;; Conflicts on atomicity, spec failures, etc. will throw exceptions and prevent after-effects. Atomicity problems
;; will retry the entire stack down to where the wrap-atomic-transaction started..
(atomic/wrap-datomic-save {:datomic/transact taudit/transact})
;; NOTE: goes before the datomic save. Queues after effects that will run via a durable queue, but only if
;; the transaction succeeded
(after-effects/wrap-durable-after-effects (fn [] after-effect-queue))
;; Resolve as late as possible, but early enough that the idempotent after-effects can know the remapping,
(atomic/wrap-resolve-transaction-data)
(wrap-schema-enforcement)
(wrap-validations)
(wrap-form-save-security)
(wrap-speculative-application (comp gcr/garbage-collect-orphans esd/rewrite-form-delta refine/run-RAD-refinements))
(wrap-retract-blank-strings)
(om/wrap-enforce-ownership)
(om/wrap-add-ownership)
(atomic/wrap-atomic-transaction atomic/marker-txn dutils/optimistic-lock-exception?)))
so, for example, the wrap-schema-enforcement
relies on the speculative-application
mw. The SA middleware uses with
to pretend to do the transaction, and then pulls all of the entities affected from the after-db and puts the after-db, the intermediate tempids, and the pulled entities into env. Then things like schema enforcement can check that things are ok.
Now, that said, save by default doesn’t “delete” anything. The delete middleware does if you’re using form-delete…so, for your case you’d augment delete-middleware to do the checks in question.
In my case I actually do have save GC orphans, but that implementation requires a bit more annotation on the model
What I need to do is to include :db/ensure <my Datomic entity spec> in the transacted data. I don't see a clear way how middleware wrapping the delete middleware would do that...
Of course instead of using Entity Spec, I could do the check myself in a middleware...
my wrap-datomic-save adds in a CAS to ensure atomic operation among multiple threads on read/write combined ops that don’t leverage transactor functions
Thank you. I will study this.
So, for example, in mine I have wrap-atomic-transaction
add a ::raw-txn to env
, and then my customized wrap-datomic-save
adds anything in ::raw-txn
into the transact
Ah, that makes sense.
We could add that pattern to the library if you want…not as the atomic support necessarily, but more as a way to allow mw elements to add things to the txn