;; next/genesis/projections/by-type.sx
;;
;; Index of activity CIDs grouped by :type. Maps type-name to a
;; list of CIDs in append order. Used by the outbox listing
;; endpoints (Step 8) for type-filtered pagination.

(DefineProjection
  :name "by-type"
  :doc "Type-name -> list of activity CIDs (append order)."
  :initial-state {}
  :fold (fn
    (state act)
    (let
      ((t (-> act :type)) (cid (-> act :cid)))
      (assoc state t (append (or (get state t) (list)) (list cid))))))
