Compare commits
3 commits
01d4799fb2
...
2b39da557c
Author | SHA1 | Date | |
---|---|---|---|
2b39da557c | |||
95214d3029 | |||
61d10bcbc6 |
2 changed files with 76 additions and 20 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]))
|
||||||
|
|
||||||
|
@ -27,20 +46,37 @@
|
||||||
(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)
|
||||||
|
|
||||||
; TODO: Allow sequences
|
(s/def ::object
|
||||||
(s/def ::object (s/or :object ::Object :link ::Link))
|
(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 ::verb core/uri-string?)
|
||||||
|
|
||||||
(s/def ::instrument (s/or :object ::Object :link ::Link))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,4 +92,21 @@
|
||||||
{:id "https://social.bla/alyssa#likes/RANDOMHASH",
|
{:id "https://social.bla/alyssa#likes/RANDOMHASH",
|
||||||
: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"})
|
|
@ -27,13 +27,16 @@
|
||||||
(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]
|
||||||
(re-matches #"[A-Z]" (str (first input))))
|
(and (string? input)
|
||||||
|
(re-matches #"[A-Z]" (str (first input)))))
|
||||||
|
|
||||||
(defn url-string? [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]
|
(defn uri-string? [input]
|
||||||
(re-matches #"\w+:(\/?\/?)[^\s]+" input))
|
(and (string? input)
|
||||||
|
(re-matches #"\w+:(\/?\/?)[^\s]+" input)))
|
||||||
|
|
||||||
(defn uri-vector? [input]
|
(defn uri-vector? [input]
|
||||||
(and (every? #(uri-string? %) input)
|
(and (every? #(uri-string? %) input)
|
||||||
|
|
Loading…
Reference in a new issue