Initial commit; nothing works yet
This commit is contained in:
commit
a599d133f4
20 changed files with 954 additions and 0 deletions
63
src/dog_and_duck/quack/quack.clj
Normal file
63
src/dog_and_duck/quack/quack.clj
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
(ns dog-and-duck.quack.quack
|
||||
"Validator for ActivityPub objects: if it walks like a duck, and it quacks like a duck..."
|
||||
;;(:require [clojure.spec.alpha as s])
|
||||
(:import [java.net URI URISyntaxException]))
|
||||
|
||||
(defn object?
|
||||
"Return `true` iff `x` is recognisably an ActivityStreams object.
|
||||
|
||||
**NOTE THAT** The ActivityStreams spec
|
||||
[says](https://www.w3.org/TR/activitystreams-core/#object):
|
||||
|
||||
> All properties are optional (including the id and type)
|
||||
|
||||
But we are *just not having that*, because otherwise we're flying blind.
|
||||
We *shall* reject objects lacking at least `:type`. Missing `:id` keys are
|
||||
tolerable because they represent transient objects, which we expect to
|
||||
handle."
|
||||
[x]
|
||||
(and (map? x) (:type x) true))
|
||||
|
||||
(object? nil)
|
||||
(object? {:type "test"})
|
||||
|
||||
(defn persistent-object?
|
||||
"`true` iff `x` is a persistent object.
|
||||
|
||||
Transient objects in ActivityPub are not required to have an `id` key, but persistent
|
||||
ones must have a key, and it must be an IRI (but normally a URI)."
|
||||
[x]
|
||||
(try
|
||||
(and (object? x) (uri? (URI. (:id x))))
|
||||
(catch URISyntaxException _ false)))
|
||||
|
||||
(persistent-object? {:type "test" :id "https://mastodon.scot/@barfilfarm"})
|
||||
|
||||
(defn actor?
|
||||
"TODO!"
|
||||
[x]
|
||||
true)
|
||||
|
||||
(def verb?
|
||||
"The set of types we will accept as verbs.
|
||||
|
||||
There's an [explicit set of allowed verbs]
|
||||
(https://www.w3.org/TR/activitystreams-vocabulary/#activity-types)."
|
||||
#{"Accept" "Add" "Announce" "Arrive" "Block" "Create" "Delete" "Dislike"
|
||||
"Flag" "Follow" "Ignore" "Invite" "Join" "Leave" "Like" "Listen" "Move"
|
||||
"Offer" "Question" "Reject" "Read" "Remove" "TentativeAccept"
|
||||
"TentativeReject" "Travel" "Undo" "Update" "View"})
|
||||
|
||||
(defn activity?
|
||||
"`true` iff `x` is an activity, else false.
|
||||
|
||||
see "
|
||||
[x]
|
||||
(try
|
||||
(and (object? x)
|
||||
(uri? (URI. ((keyword "@context") x)))
|
||||
(string? (:summary x))
|
||||
(actor? (:actor x))
|
||||
(verb? (:type x))
|
||||
(or (object? (:object x)) (uri? (URI. x))))
|
||||
(catch URISyntaxException _ false)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue