Compare commits

..

No commits in common. "2b39da557cd7c1b63dadc3031f4fc7f8a11bdb34" and "01d4799fb2d5769e1c31144ef791cc26e4529b81" have entirely different histories.

2 changed files with 20 additions and 76 deletions

View file

@ -2,36 +2,17 @@
(: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/and (s/keys :map (s/keys
:req-un [::id ::type] :req-un [::id ::type] ;type darf nicht "Link" sein
: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? %) (contains? objectAndLinkTypes %))) (s/def ::type #(or (core/uri-string? %) (= % "Link")))
(s/def ::Link (s/and (s/keys (s/def ::Link (s/keys
:req-un [::type] :req-un [::type] ; type muss "Link" sein
: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]))
@ -46,37 +27,20 @@
(s/def ::attributedTo (s/or :object ::Object :link ::Link)) (s/def ::attributedTo (s/or :object ::Object :link ::Link))
(s/def ::actor ::attributedTo) (s/def ::actor ::attributedTo)
(s/def ::object ; TODO: Allow sequences
(s/or :object ::Object (s/def ::object (s/or :object ::Object :link ::Link))
:link ::Link
:objects (s/coll-of ::Object)
:links (s/coll-of ::Link)))
(s/def ::result (s/def ::result (s/or :object ::Object :link ::Link))
(s/or :object ::Object
:link ::Link
:objects (s/coll-of ::Object)
:links (s/coll-of ::Link)))
(s/def ::target (s/def ::target (s/or :object ::Object :link ::Link))
(s/or :object ::Object
:link ::Link
:objects (s/coll-of ::Object)
:links (s/coll-of ::Link)))
(s/def ::origin (s/def ::origin (s/or :object ::Object :link ::Link))
(s/or :object ::Object
:link ::Link
:objects (s/coll-of ::Object)
:links (s/coll-of ::Link)))
(s/def ::instrument (s/def ::instrument (s/or :object ::Object :link ::Link))
(s/or :object ::Object
:link ::Link
:objects (s/coll-of ::Object)
:links (s/coll-of ::Link)))
(s/def ::verb core/uri-string?) (s/def ::verb uri?)
(s/def ::instrument (s/or :object ::Object :link ::Link))
@ -93,20 +57,3 @@
: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"})

View file

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