2023-08-07 06:34:39 +00:00
|
|
|
(ns org.domaindrivenarchitecture.fed-poc.activitystreams2-legacy
|
2023-07-06 11:31:24 +00:00
|
|
|
(:require [clojure.spec.alpha :as s]
|
2023-08-07 06:34:39 +00:00
|
|
|
[org.domaindrivenarchitecture.fed-poc.owl :as owl]
|
|
|
|
[org.domaindrivenarchitecture.fed-poc.core :as core]))
|
2023-06-30 13:01:51 +00:00
|
|
|
|
2023-07-06 12:10:39 +00:00
|
|
|
; TODO: We could do these with multispec, but that is too much for a POC
|
|
|
|
(def objectAndLinkTypes #{; Object Types
|
2023-07-06 12:15:36 +00:00
|
|
|
"Article"
|
|
|
|
"Audio"
|
2023-07-14 14:48:28 +00:00
|
|
|
"Collection"
|
2023-07-06 12:15:36 +00:00
|
|
|
"Document"
|
|
|
|
"Event"
|
|
|
|
"Image"
|
|
|
|
"Note"
|
2023-07-14 14:48:28 +00:00
|
|
|
"Object"
|
|
|
|
"OrderedCollection"
|
2023-07-06 12:15:36 +00:00
|
|
|
"Page"
|
|
|
|
"Place"
|
|
|
|
"Profile"
|
|
|
|
"Relationship"
|
|
|
|
"Tombstone"
|
|
|
|
"Video"
|
2023-07-21 15:43:10 +00:00
|
|
|
"Link"
|
2023-07-06 12:10:39 +00:00
|
|
|
; Link Types
|
2023-07-06 12:15:36 +00:00
|
|
|
"Mention"})
|
2023-07-06 12:10:39 +00:00
|
|
|
|
2023-07-14 14:48:28 +00:00
|
|
|
(defn match-type
|
2023-07-06 13:00:40 +00:00
|
|
|
[type]
|
|
|
|
#(= (:type %) type))
|
|
|
|
|
2023-06-30 13:25:23 +00:00
|
|
|
(s/def ::Object (s/or
|
2023-07-06 11:31:24 +00:00
|
|
|
:uri core/uri-string?
|
2023-07-06 12:10:39 +00:00
|
|
|
:map (s/and (s/keys
|
|
|
|
:req-un [::id ::type]
|
2023-07-18 07:18:40 +00:00
|
|
|
:opt-un [::attributedTo ::und-mehr])
|
|
|
|
(match-type "Object"))))
|
2023-07-21 15:43:10 +00:00
|
|
|
|
2023-07-18 07:18:40 +00:00
|
|
|
;http://www.w3.org/ns/activitystreams#id
|
|
|
|
;TODO: how do we translate this? rdfs:domain [a owl:Class ; owl:unionOf (as:Link as:Object)]
|
2023-07-21 08:12:08 +00:00
|
|
|
;TODO evtl sind ::owl/FunctionalProperty, ::owl/DatatypeProperty, ::owl/DeprecatedProperty nur meta informationen?
|
2023-07-18 07:18:40 +00:00
|
|
|
(s/def ::id (s/and ::owl/FunctionalProperty
|
|
|
|
::owl/DatatypeProperty
|
|
|
|
::owl/DeprecatedProperty
|
|
|
|
core/uri-string?))
|
2023-07-14 14:48:28 +00:00
|
|
|
|
2023-07-21 08:12:08 +00:00
|
|
|
;TODO: we will need such a predicate ...
|
|
|
|
;(defn-spec isFunctional? bool?
|
|
|
|
; [spec keyword?]
|
|
|
|
; (search-in-meta spec))
|
2023-07-14 14:48:28 +00:00
|
|
|
|
|
|
|
; TODO: type can have multiple values!! Affects also the fct match-type and all specs that uses it!
|
2023-07-06 12:10:39 +00:00
|
|
|
(s/def ::type #(or (core/uri-string? %) (contains? objectAndLinkTypes %)))
|
2023-06-30 13:01:51 +00:00
|
|
|
|
2023-07-06 12:10:39 +00:00
|
|
|
(s/def ::Link (s/and (s/keys
|
|
|
|
:req-un [::type]
|
|
|
|
:opt-un [::attributedTo ::und-mehr])
|
2023-07-06 13:00:40 +00:00
|
|
|
(match-type "Link")))
|
2023-06-30 13:01:51 +00:00
|
|
|
|
|
|
|
(s/def ::Relationship (s/keys :req-un [::object ::und-mehr]))
|
|
|
|
|
2023-07-14 14:48:28 +00:00
|
|
|
; #### Collection ####
|
|
|
|
(s/def ::Collection (s/and ::Object
|
|
|
|
(s/keys
|
|
|
|
:opt-un [::totalItems ::current ::first ::last ; FUNCTIONAL properties!
|
|
|
|
::items]) ;"items" is not a FUNCTIONAL property!
|
|
|
|
(match-type "Collection")))
|
|
|
|
; Side note: A property marked as FUNCTIONAL does not mean that this property is required for the respective Object.
|
|
|
|
; Example: The property "replies" is FUNCTIONAL for "Object" but is an optional property for "Object".
|
|
|
|
|
|
|
|
(s/def ::OrderedCollection (s/and ::Collection
|
|
|
|
(match-type "OrderedCollection")))
|
|
|
|
|
2023-07-14 11:47:59 +00:00
|
|
|
; #### NOTE ####
|
|
|
|
; Specialities of mastodon statuses: https://docs.joinmastodon.org/spec/activitypub/#status
|
|
|
|
(s/def ::Note (s/and ::Object
|
2023-07-18 06:30:09 +00:00
|
|
|
;(match-type "Note")
|
2023-07-14 14:48:28 +00:00
|
|
|
(s/keys
|
|
|
|
:opt-un [::likes])))
|
|
|
|
|
|
|
|
(s/def ::likes (s/or :collection ::Collection
|
|
|
|
:ordered-collection ::OrderedCollection))
|
2023-07-14 11:47:59 +00:00
|
|
|
|
2023-06-30 13:01:51 +00:00
|
|
|
; #### ACTIVITY ####
|
2023-07-14 14:48:28 +00:00
|
|
|
(s/def ::Activity (s/and
|
2023-06-30 13:01:51 +00:00
|
|
|
::Object
|
|
|
|
(s/keys
|
|
|
|
:req-un [::actor ::object]
|
|
|
|
:opt-un [::result ::target ::origin ::instrument
|
|
|
|
::verb])))
|
|
|
|
; "IntransitiveActivity" erbt von Activity, aber ohne ::object
|
|
|
|
|
2023-07-06 12:37:49 +00:00
|
|
|
(s/def ::Property (s/or :object ::Object
|
|
|
|
:link ::Link
|
2023-07-06 12:44:26 +00:00
|
|
|
:collection (s/coll-of (s/or :object ::Object :link ::Link))))
|
|
|
|
|
|
|
|
(s/def ::attributedTo ::Property)
|
|
|
|
(s/def ::actor ::attributedTo)
|
|
|
|
|
2023-07-06 12:15:36 +00:00
|
|
|
(s/def ::object
|
2023-07-06 12:37:49 +00:00
|
|
|
::Property)
|
2023-07-06 12:15:36 +00:00
|
|
|
|
|
|
|
(s/def ::result
|
2023-07-06 12:37:49 +00:00
|
|
|
::Property)
|
2023-07-06 12:15:36 +00:00
|
|
|
|
|
|
|
(s/def ::target
|
2023-07-06 12:37:49 +00:00
|
|
|
::Property)
|
2023-07-06 12:15:36 +00:00
|
|
|
|
|
|
|
(s/def ::origin
|
2023-07-06 12:37:49 +00:00
|
|
|
::Property)
|
2023-07-06 12:15:36 +00:00
|
|
|
|
|
|
|
(s/def ::instrument
|
2023-07-06 12:37:49 +00:00
|
|
|
::Property)
|
2023-07-06 12:15:36 +00:00
|
|
|
|
|
|
|
(s/def ::verb core/uri-string?)
|
2023-06-30 13:01:51 +00:00
|
|
|
|
|
|
|
; #### LIKE ####
|
2023-07-06 13:00:40 +00:00
|
|
|
(s/def ::Like (s/and ::Activity
|
|
|
|
(match-type "Like")))
|
2023-06-30 13:01:51 +00:00
|
|
|
|
|
|
|
; Was beim Type Activity optional und required ist, ist abhängig vom Aktivitätstyp.
|
|
|
|
; Bspw brauch ein Like einen actor und den type "Like" und (xor) target/object.
|
|
|
|
; Aber die "IntransitiveActivity" (die alles von Activity erbt außer "object") vom Type "Question" besitzt keinen "actor".
|
|
|
|
|
|
|
|
(def maybeLike?
|
|
|
|
{:id "https://social.bla/alyssa#likes/RANDOMHASH",
|
|
|
|
:type "Like",
|
|
|
|
:actor "https://social.bla/alyssa",
|
2023-07-06 12:10:39 +00:00
|
|
|
: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"})
|