Compare commits

...

3 commits

2 changed files with 76 additions and 20 deletions

View file

@ -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]))
@ -27,20 +46,37 @@
(s/def ::attributedTo (s/or :object ::Object :link ::Link))
(s/def ::actor ::attributedTo)
; TODO: Allow sequences
(s/def ::object (s/or :object ::Object :link ::Link))
(s/def ::object
(s/or :object ::Object
:link ::Link
:objects (s/coll-of ::Object)
:links (s/coll-of ::Link)))
(s/def ::result (s/or :object ::Object :link ::Link))
(s/def ::result
(s/or :object ::Object
:link ::Link
:objects (s/coll-of ::Object)
:links (s/coll-of ::Link)))
(s/def ::target (s/or :object ::Object :link ::Link))
(s/def ::target
(s/or :object ::Object
:link ::Link
:objects (s/coll-of ::Object)
:links (s/coll-of ::Link)))
(s/def ::origin (s/or :object ::Object :link ::Link))
(s/def ::origin
(s/or :object ::Object
:link ::Link
:objects (s/coll-of ::Object)
:links (s/coll-of ::Link)))
(s/def ::instrument (s/or :object ::Object :link ::Link))
(s/def ::instrument
(s/or :object ::Object
:link ::Link
:objects (s/coll-of ::Object)
:links (s/coll-of ::Link)))
(s/def ::verb uri?)
(s/def ::instrument (s/or :object ::Object :link ::Link))
(s/def ::verb core/uri-string?)
@ -56,4 +92,21 @@
{:id "https://social.bla/alyssa#likes/RANDOMHASH",
:type "Like",
: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"})

View file

@ -27,13 +27,16 @@
(def parsed-rdf-syntax (parse (slurp cm/activitystreams-ttl)))
(defn type-string? [input]
(re-matches #"[A-Z]" (str (first input))))
(and (string? input)
(re-matches #"[A-Z]" (str (first input)))))
(defn url-string? [input]
(re-matches #"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)" input))
(and (string? input)
(re-matches #"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)" input)))
(defn uri-string? [input]
(re-matches #"\w+:(\/?\/?)[^\s]+" input))
(and (string? input)
(re-matches #"\w+:(\/?\/?)[^\s]+" input)))
(defn uri-vector? [input]
(and (every? #(uri-string? %) input)