Implement simple specs and like map generation

This commit is contained in:
erik 2023-06-22 15:44:55 +02:00
parent 6f8b77c17e
commit cc641bfe7f

View file

@ -4,11 +4,13 @@
[quoll.raphael.core :refer [parse]]
[org.domaindrivenarchitecture.activity-pub-poc.common :as cm]
[clojure.spec.alpha :as s]
[orchestra.core :refer [defn-spec]]
[clojure.inspector :as ins]
[hato.client :as hato]
[clojure.string :as st]
[clojure.walk :as walk]
[clojure.string :as str]))
[clojure.string :as str]
[lambdaisland.uri :as uri]))
(def team-url "https://social.meissa-gmbh.de/users/team")
(def like-url "https://www.w3.org/ns/activitystreams#Like")
@ -26,17 +28,71 @@
(defn type-string? [input]
(re-matches #"[A-Z]" (str (first input))))
(defn uri-string? [input]
(re-matches #"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)" input))
(defn uri-vector? [input]
(and (every? #(uri? %) input)
(vector? input)))
(def context "@context")
(def type-string "type")
(def id-uri "id")
(def to-uri "to")
(def actor "actor")
(def object "object")
; Specs for a like
(s/def ::context uri?)
(s/def ::type type-string?)
(s/def ::id uri?)
(s/def ::to uri-vector?)
(s/def ::actor uri?)
(s/def ::object uri?)
(s/def context uri-string?)
(s/def type-string type-string?)
(s/def id-uri uri-string?)
(s/def to-uri uri-vector?)
(s/def actor uri-string?)
(s/def object uri-string?)
(s/def ::to uri-string?)
(s/def ::target string?)
(s/def ::from uri-string?)
(def like? (s/keys :req-un [context
type-string
id-uri
to-uri
actor
object]))
(def like-data? (s/keys :req-un [::to ::target ::from]))
(def activity-streams-context "https://www.w3.org/ns/activitystreams")
(def like-data
{:to "https://chatty.bla/ben/"
:target "posts/234s23-2g34234-2hhj536"
:from "https://social.bla/alyssa/"})
(defn generate-id-from-object [from]
(str from "out" "/" "sdfsd44243g324g3455"))
(defn-spec generate-like-map like?
[input-map like-data?]
(assoc {}
"@context" activity-streams-context
"type" "Like"
"id" (generate-id-from-object (:from input-map))
"to" (:to input-map)
"actor" (:from input-map)
"object" (:target input-map)))
; ToDo
; Prädikat das langString parsen/validieren kann, evtl auch für xsd:string