diff --git a/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.clj b/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.clj index d74ac6d..b410ecc 100644 --- a/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.clj +++ b/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.clj @@ -2,17 +2,36 @@ (:require [clojure.spec.alpha :as s] [org.domaindrivenarchitecture.activity-pub-poc.core :as core])) +; TODO: We could do these with multispec, but that is too much for a POC +(def objectAndLinkTypes #{; Object Types + "Article" + "Audio" + "Document" + "Event" + "Image" + "Note" + "Page" + "Place" + "Profile" + "Relationship" + "Tombstone" + "Video" + ; Link Types + "Mention"}) + (s/def ::Object (s/or :uri core/uri-string? - :map (s/keys - :req-un [::id ::type] ;type darf nicht "Link" sein - :opt-un [::attributedTo ::und-mehr]))) + :map (s/and (s/keys + :req-un [::id ::type] + :opt-un [::attributedTo ::und-mehr]) + #(not (= (:type %) "Link"))))) (s/def ::id core/uri-string?) -(s/def ::type #(or (core/uri-string? %) (= % "Link"))) +(s/def ::type #(or (core/uri-string? %) (contains? objectAndLinkTypes %))) -(s/def ::Link (s/keys - :req-un [::type] ; type muss "Link" sein - :opt-un [::attributedTo ::und-mehr])) +(s/def ::Link (s/and (s/keys + :req-un [::type] + :opt-un [::attributedTo ::und-mehr]) + #(= (:type %) "Link"))) (s/def ::Relationship (s/keys :req-un [::object ::und-mehr])) @@ -56,4 +75,21 @@ {:id "https://social.bla/alyssa#likes/RANDOMHASH", :type "Like", :actor "https://social.bla/alyssa", - :object "https://chatty.bla/ben/posts/234s23-2g34234-2hhj536"}) \ No newline at end of file + :object "https://chatty.bla/ben/posts/234s23-2g34234-2hhj536"}) + +(def testLink + {:context "https://www.w3.org/ns/activitystreams", + :type "Link", + :href "http://example.org/abc", + :hreflang "en", + :mediaType "text/html", + :name "An example link"}) + +(def testObject + {:context "https://www.w3.org/ns/activitystreams", + :type "Note", + :id "https://social.bla/alyssa", + :href "http://example.org/abc", + :hreflang "en", + :mediaType "text/html", + :name "An example object"}) \ No newline at end of file