Match Object and Link spec more closely
This commit is contained in:
parent
61d10bcbc6
commit
95214d3029
1 changed files with 44 additions and 8 deletions
|
@ -2,17 +2,36 @@
|
||||||
(:require [clojure.spec.alpha :as s]
|
(:require [clojure.spec.alpha :as s]
|
||||||
[org.domaindrivenarchitecture.activity-pub-poc.core :as core]))
|
[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
|
(s/def ::Object (s/or
|
||||||
:uri core/uri-string?
|
:uri core/uri-string?
|
||||||
:map (s/keys
|
:map (s/and (s/keys
|
||||||
:req-un [::id ::type] ;type darf nicht "Link" sein
|
:req-un [::id ::type]
|
||||||
:opt-un [::attributedTo ::und-mehr])))
|
:opt-un [::attributedTo ::und-mehr])
|
||||||
|
#(not (= (:type %) "Link")))))
|
||||||
(s/def ::id core/uri-string?)
|
(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
|
(s/def ::Link (s/and (s/keys
|
||||||
:req-un [::type] ; type muss "Link" sein
|
:req-un [::type]
|
||||||
:opt-un [::attributedTo ::und-mehr]))
|
:opt-un [::attributedTo ::und-mehr])
|
||||||
|
#(= (:type %) "Link")))
|
||||||
|
|
||||||
(s/def ::Relationship (s/keys :req-un [::object ::und-mehr]))
|
(s/def ::Relationship (s/keys :req-un [::object ::und-mehr]))
|
||||||
|
|
||||||
|
@ -57,3 +76,20 @@
|
||||||
:type "Like",
|
:type "Like",
|
||||||
:actor "https://social.bla/alyssa",
|
:actor "https://social.bla/alyssa",
|
||||||
:object "https://chatty.bla/ben/posts/234s23-2g34234-2hhj536"})
|
: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"})
|
Loading…
Reference in a new issue