host P0.1: publish-activity contract for federated composition-flows
Business logic as federated composition-flows (plans/business-logic-fed-flows.md). P0.1: the
host describes a published post as a fed-sx activity — host/blog--publish-activity(slug) →
{:type "create" :actor "site" :id <CID> :object {:type "article" :slug :category}} — the
exact shape next/'s trigger machinery consumes (verified: next/tests/triggers_e2e.sh 10/10).
category (drives the flow branch: newsletter suspends / urgent fires / else skip) comes from
the "category" field-value, else the first tag, else "urgent". + host/blog--post-category.
Design decided: activity log = every CID delta (event source); triggers = declared subscriptions
(DefineTrigger); flows hybrid (SX composition for simple via the execute-fold, named Erlang flows
for complex); federated execution = Erlang (next/); the type carries content+relations+behavior.
blog 200/200 (+3: contract, category fallback, missing-post nil).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -107,6 +107,28 @@
|
||||
(fn (acc slug) (if acc acc (if (= (host/blog-cid slug) cid) slug acc)))
|
||||
nil (host/blog-slugs))))
|
||||
|
||||
;; ── business logic as federated composition-flows (plans/business-logic-fed-flows.md) ──
|
||||
;; P0.1: the PUBLISH-ACTIVITY contract. A published post is described as a fed-sx activity —
|
||||
;; the same shape next/'s trigger machinery consumes ({:type verb :actor :id CID :object …}).
|
||||
;; The trigger (on-publish → a flow, e.g. blog_publish_digest) fires on a matching activity.
|
||||
;; category (drives the flow's branch: newsletter suspends, urgent fires now, else skip) comes
|
||||
;; from the post's "category" field-value, else its first tag, else "urgent" (fires the demo).
|
||||
(define host/blog--post-category
|
||||
(fn (slug)
|
||||
(let ((fc (get (host/blog-field-values-of slug) "category")))
|
||||
(if (and fc (not (= fc ""))) fc
|
||||
(let ((tags (host/blog-out slug "tagged")))
|
||||
(if (> (len tags) 0) (first tags) "urgent"))))))
|
||||
(define host/blog--publish-activity
|
||||
(fn (slug)
|
||||
(let ((r (host/blog-get slug)))
|
||||
(if (nil? r) nil
|
||||
{:type "create" ;; publishing = the article enters the fed world
|
||||
:actor "site" ;; P0: a fixed site actor; per-author later
|
||||
:id (host/blog-cid slug) ;; the object's content CID
|
||||
:object {:type "article" :slug slug
|
||||
:category (host/blog--post-category slug)}}))))
|
||||
|
||||
;; ── render ──────────────────────────────────────────────────────────
|
||||
;; A post's sx_content is SX element markup -> HTML via render-page (which supplies
|
||||
;; the server env so components resolve + keyword attrs are kept).
|
||||
|
||||
Reference in New Issue
Block a user